Pass IDs to pre_get_posts query in function

后端 未结 2 932
滥情空心
滥情空心 2021-01-27 04:15

I am trying to pass the post ids to the function\'s query->set and function will return the posts.

add_action( \'pre_get_posts\', \'query_booked_posts\' );

func         


        
2条回答
  •  执念已碎
    2021-01-27 04:56

    Except the extra array() over $results_separated, in my case I had to apply

    if (!$query->is_main_query()) {
        return $query;
    }
    

    at the top of my function (found it in, otherwise, queries inside would be executed for several times and not properly. Comments in the answer helped me to figure this out.

提交回复
热议问题