post_grid_ajax_query_args

You can add more query arguments by filter hook that’s supported by WP_Query

function post_grid_ajax_query_args_20200429($query_args, $grid_id){
    
  $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_ajax_query_args','post_grid_ajax_query_args_20200429');

This filter hook will affect all of your post grid created on your site.

function post_grid_ajax_query_args_20200429($query_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_ajax_query_args','post_grid_ajax_query_args_20200429',10,2);

 

Query post on the author page

function post_grid_ajax_query_args_20200429($query_args, $grid_id){

    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_ajax_query_args','post_grid_ajax_query_args_20200429');

 

Display on the single post page

function post_grid_ajax_query_args_20200429($query_args, $grid_id){

    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_ajax_query_args','post_grid_ajax_query_args_20200429');

 

Load different posts per page on mobile devices.

function post_grid_ajax_query_args_20200429($query_args, $grid_id){

    if(wp_is_mobile()):
        $query_args['posts_per_page'] = 2;
    endif;

    return $query_args;
}

add_filter('post_grid_ajax_query_args','post_grid_ajax_query_args_20200429');