Add Filter posts_results using WP_Query (2 posts)

  1. Giovanni Putignano
    Posted 2 years 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
    Posted 2 years 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