Support » Plugins » Hacks » Add Filter posts_results using WP_Query

  • 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;
    }

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    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.

Viewing 1 replies (of 1 total)
  • The topic ‘Add Filter posts_results using WP_Query’ is closed to new replies.