Essential Grid Filter by Author

Hi,

I’ve tried following the directions of this topic thread:

It is not working for me…
This is what I’ve done so far:

  1. Created a grid with all post categories are selected
  2. The grid ID is 58
  3. The author ID is 6
  4. I have added it to a page using the element “Classic Essential Grid”
  5. Added the code from support thread into functions.php (updating grid and author numbers) --> see below
  6. The grid is showing all posts; no filtering by author.

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 == 58) return false;
return true;

}

function eg_mod_query($query, $grid_id){

// show only posts from specific author
if($grid_id == 58){

$query[‘meta_query’] = array( ‘author’ => ‘6’, ‘orderby’ => ‘post_date’, ‘order’ => ‘ASC’ );

}

return $query;

}

What am I doing wrong?

Thanks.
Diego M.

Hello Diego,

Thank you for the very detailed post.

Instead of using the PHP function code, you can make use of the additional parameter settings in your grid.

Author by ID:

Author by Nice Name:

Hope this helps.

Hi RueNel,

I followed your directions:

  • I deleted the code form functions.php
  • Deselected all categories
  • Added ‘author = 6’ to the parameters field
  • It didn’t work. The grid is showing all posts, when it should be showing only 4.

Here are a few screenshots:

Here you see the grid settings and parameters (highlighted in yellow).

Here you see the 4 posts assigned to user 6 and that it is really user id =6 (lower part of screenshot).

As you see all is there, yet it is not working as needed.

What could be the issue?

Thanks,

Diego M.

Hi Diego,

Could you try it without special characters and spacing? Example,

author=6 instead of 'author = 6'.

Please check common sample here too https://www.themepunch.com/faq/grid-custom-order/

Thanks!

Hi Rad,
Thank you sooo much!
That simple change fixed the problem.

Diego M.

You’re welcome!
Thanks for letting us know that it has worked for you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.