Hello,
I would like to make a grid that pulls only posts from a single author.
What is the code I write in ‘Additional parameters’ to achieve this? I have searched but did not find a clear answer.
Thanks,
Sophie
Hello,
I would like to make a grid that pulls only posts from a single author.
What is the code I write in ‘Additional parameters’ to achieve this? I have searched but did not find a clear answer.
Thanks,
Sophie
Hello @SophiePeirce,
Thanks for writing in! 
That’s possible with Essential Grid plus custom query: Advanced Additional Parameters
All we need to is change the parameters present on the $query variable.
First, add the parameters on query like this:
if($grid_id == YOUR_GRID_ID) {
$query['meta_query'] = array( 'author' => 'THE_AUTHOR_ID', 'orderby' => 'post_date', 'order' => 'ASC' );
}
Then change the value of YOUR_GRID_ID and the THE_AUTHOR_ID to their respective values.
You can use the full code below. Kindly add this to your functions.php. Please don’t forget to update the ID’s:
// code can be added to your themes functions.php file
add_filter('essgrid_query_caching', 'eg_stop_caching', 10, 2);
add_filter('essgrid_get_posts', 'eg_mod_query', 10, 2);
// turn off caching for your grid
function eg_stop_caching($do_cache, $grid_id) {
if($grid_id == YOUR_GRID_ID) return false;
return true;
}
function eg_mod_query($query, $grid_id){
// show only posts from specific author
if($grid_id == YOUR_GRID_ID){
$query['meta_query'] = array( 'author' => 'THE_AUTHOR_ID', 'orderby' => 'post_date', 'order' => 'ASC' );
}
return $query;
}
Hope that helps.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.