You can add more query arguments by filter hook that’s supported by WP_Query
function post_grid_query_args_20200429($query_args, $args){ $current_post_id = get_the_ID(); $extra_query = array ( 'post__not_in' => array($current_post_id), ); return array_merge($query_args, $extra_query); } add_filter('post_grid_query_args','post_grid_query_args_20200429', 10, 2);
This filter hook will affect all of your post grid created on your site. you can pass post grid id to apply on any specific post grid.
function post_grid_query_args_20200429($query_args, $args){ $grid_id = isset($args['grid_id']) ? $args['grid_id'] : ''; if($grid_id==7){ $extra_query = array ( 'post__in' => array('1241'), ); $query_args = array_merge($query_args, $extra_query); } return $query_args; } add_filter('post_grid_query_args','post_grid_query_args_20200429',10,2);
Query post on the author page
function post_grid_query_args_20200429($query_args, $args){ if(is_author()){ $author = get_queried_object(); $author_id = isset($author->ID) ? $author->ID : ''; if(!empty($author_id)) $query_args['author'] = $author->ID; } return $query_args; } add_filter('post_grid_query_args','post_grid_query_args_20200429', 10, 2);
Display on the single post page
function post_grid_query_args_20200429($query_args, $args){ if(is_singular()): $current_post_id = get_the_ID(); $query_args['post__not_in'] = array($current_post_id); endif; return $query_args; } add_filter('post_grid_query_args','post_grid_query_args_20200429', 10, 2);
Load different posts per page on mobile devices.
function post_grid_query_args_20200429($query_args, $args){ if(wp_is_mobile()): $query_args['posts_per_page'] = 2; endif; return $query_args; } add_filter('post_grid_query_args','post_grid_query_args_20200429',10 ,2);