Help with Essential Grid Post-Based (Category AND Tag)

Hi there, i have a question about the Essential Grid plugin included in X.
Using the theme punch documentation I was able to create a working post-based grid:
https://www.themepunch.com/essgrid-doc/core-anatomy-of-an-essential-grid/

The Grid correctly displays posts from a single category.

There is an unexepected result, however, when trying to combine Categories AND Tags.

Zero results!

I know there are posts that match the necessary conditions but none appear.

The documentation clearly says it is possible but no luck.

Can you reproduce a working example of a post-based grid that correctly displays posts from a Category (at least one) AND a Tag (or multiple Tags) ?

Thanks!

Hi There,

Thank you for writing in, please confirm that you are fully updated? (Theme and Plugins)

You can find the latest version numbers here Then you can compare them to what’s installed on your site.

If you find anything to be out of date, you can review our update guide.

If you do confirm the latest versions, please do a test plugin conflict. You can do this by deactivating all third-party plugins, and see if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

If the issue persists, please provide us login credentials in a secure note so we can take a closer look.

Cheers!

Hi there,
The latest versions of X and Essential Grid are installed.
No plugin conflict detected.
You can see the issue below:

Hi @Mbzo

First you need to only choose your desired category in Essential Grid settings with relationship OR, then add this code to your child theme functions.php file:

add_filter('essgrid_modify_posts', 'eg_modify_post', 10, 2);
 
function eg_modify_post($posts, $grid_id){
 
    $filterPosts = array();
 
    foreach($posts as $post) {
 
        foreach($post['post_category'] as $cat) {
            if($cat === 5) {
 								 if (in_array('combate ao contrabando', $post['tags_input'])){
                $filterPosts[] = $post;
                break;
              }
            }
        }
    }
    return $filterPosts;
}

If for any reason this code doesn’t work, please provide us with your FTP login details in Secure Note for further investigation.

Reference:

https://www.themepunch.com/faq/combine-and-with-or-for-category-relation-advanced/

Thanks.

Hi Alaa, thanks for your assistance.
Your code certainly works. I read the Advanced instructions in the Grid documentation but the example was for an OR scenario.
Is there a working example using the AND condition? It would be good to make grids without needing to alter the functions.php file.

There is a very nice plugin called ContentViews that might also work: https://wordpress.org/plugins/content-views-query-and-display-post-page/

Thanks again for your help!

Hello There,

Unfortunately, the code is needed to achieve what you want.
Using AND directly without the code means, that the grid will look for a post with this specific CATEGORIES AND TAGS. It will only be true if a specific post belongs to specific category and also has specific tag. So if a post has this define category only and no set tag it will not be true thus you are seeing zero results. Feel free to use a plugin if it works on your situation. Note that issues with third party plugin is outside the scope of our support. Thank you.

Thanks, Lely, for the clarification. FYI, I tested the grid using the AND condition where there are posts that match exactly specific conditions but was not able to see any results. I will try to reproduce the error and let you know.

You’re most welcome.
Please let us know the results if there are any errors.

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