• Resolved lauratraveler

    (@lauratraveler)


    Hi,

    I’m looking into using the post grid and I have 2 questions:

    1. How can I make the title tag a <p> instead of a header from <h1> to <h6> ?
    It doesn’t always make sense to use a header for the title tag and using the wrong header tag can easily break the hierarchy of the headers within a post.

    2. How can I exclude the current post where the block is placed?

    Thank you!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Team Brainstorm Force

    (@brainstormteam)

    Hey @lauratraveler ,

    Thank you for reaching us out.
    Below is the explanation to your queries:

    1) Currently, we don’t have such an option. I will ask my team to make it possible for you.

    2) Yes, you can do that using UAG filter – https://www.ultimategutenberg.com/docs/filters-actions-for-post/#uagb_post_query_args_{post_block_type}

    You need to add this to your functins.php file –

    function filter_post_query( $query_args, $attributes) {
        // Modify $query_args values.
        $query_args['post__not_in'] = get_the_ID();
        return $query_args;
    } 
    add_filter( 'uagb_post_query_args_grid', 'filter_post_query', 10, 2 );

    I hope that helps you.

    Regards,
    Vrunda Kansara

    Thread Starter lauratraveler

    (@lauratraveler)

    Thank you, @brainstormteam

    So I placed the function you gave me in the functions.php file but then the whole block doesn’t show.

    Basically I was trying to use the Post Grid to display related posts at the end of an article and I wanted to exclude the post that a user is currently reading from the Post Grid.

    Say someone is reading a post and the post has tag ‘A’. In the Post Grid at the end of the article, I want to display other related posts that belong to tag ‘A’. But the post the user is currently reading will most likely show in the Post Grid, especially if the tag doesn’t have many articles. What I wanted to do is not display the post that the user is currently reading in the Post Grid. Is this possible?

    Thread Starter lauratraveler

    (@lauratraveler)

    PS: If I change [‘post__not_in’] to [‘post_not_in’] (remove the double underscore) the block shows again but there’s no difference between using the function and not using it at all and the current post is still displayed.

    Plugin Support Team Brainstorm Force

    (@brainstormteam)

    Hey @lauratraveler ,

    Yes, absolutely I get your point and this is possible. Please reach us out here so that we can help you better.

    Looking forward to resolving your issue ASAP.

    Regards,
    Vrunda Kansara

    createdyanne

    (@webstorybuilder)

    Hello, for those who arrived here from Google or other search, the following snippet modification worked for me:

    /**
     * Filter out current page on UAG Post Grid
     */
    function filter_post_query( $query_args, $attributes) {
        // Modify $query_args values.
        $query_args['post__not_in'][] = get_the_ID();
        return $query_args;
    	print_r($query_args);
    } 
    add_filter( 'uagb_post_query_args_grid', 'filter_post_query', 10, 2 );
    

    According to the debug message, $post__not_in looks for an array, so I added [] after $query_args['post__not_in']. With this addition, the Post Grid displays the expected items.

    Plugin Support Team Brainstorm Force

    (@brainstormteam)

    Hey @webstorybuilder ,

    +1 to the solution you provided.
    That indeed should work.

    Regards,
    Vrunda Kansara

    Thread Starter lauratraveler

    (@lauratraveler)

    Thanks, @webstorybuilder. That worked!

    createdyanne

    (@webstorybuilder)

    FYI, just realized that a bit of debugging code was still in the snippet that I posted. Please remove the print_r.

    Thread Starter lauratraveler

    (@lauratraveler)

    Thank you @webstorybuilder ??

    Thread Starter lauratraveler

    (@lauratraveler)

    Btw, @webstorybuilder does filtering the posts by category or tags (hence inheriting the category of the current post) use the same function as above but with wrapping the

    $query_args['post__not_in'][] = get_the_ID();
    return $query_args;

    into an if? I’ve been struggling to figure this out for over a week but no luck. Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Post grid – make title p and exclude current post’ is closed to new replies.