WordPress.org

Ready to get started?Download WordPress

Forums

Add Filter posts_results using WP_Query (2 posts)

  1. Giovanni Putignano
    Member
    Posted 1 year ago #

    I'm learning how to create Plugin in WordPress and I have a question about how to filter posts using 'posts_results' hook and WP_Query inside the function.
    How can I filter $results in the code below by WP_Query?

    add_filter( 'posts_results', 'gp_custom_home_page_posts' );
    function gp_custom_home_page_posts( $results ) {
    ....
    return $results;
    }

  2. bcworkz
    Member
    Posted 1 year ago #

    You are passed an array with two elements, the first is an array of post objects returned by the query, the second is the query object itself. Manipulate the data contained as you see fit and then return it.

Topic Closed

This topic has been closed to new replies.

About this Topic