[Resolved] Query Loop

Home Forums Support [Resolved] Query Loop

Home Forums Support Query Loop

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2272021
    Adarsha

    Hey, I am using query loop for related posts via elements.
    But the post under which I use also shows the same post in related post.
    Is there a option to disable showing the main post?

    I was using WP show posts till now and it had a way to hide the main post.

    #2272206
    Fernando
    Customer Support

    Hi Adarsha,

    To clarify, are you referring to excluding the current post in your Query Loop Block?

    If so, you can use a filter to do as such.

    Add my-class-name to the Post Template Block as such: https://share.getcloudapp.com/qGuOrgnZ

    Then add this PHP snippet:

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
        if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-class-name' ) !== false ) {
            
    		$query_args['post__not_in'] = [get_the_ID()];
        }
    
        return $query_args;
    }, 10, 2 );

    Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets

    Hope this helps!

    #2273934
    Adarsha

    Snippets plugin has option to “run the php sitewide”
    Should I do that?

    #2274014
    Ying
    Staff
    Customer Support

    Yes.

    #2274071
    Adarsha

    I’m not sure how to add the “my-class-name”

    I am using elements for related posts.
    So for each category, there is new element.

    I tried adding it to the element and that does not hide.

    #2274081
    Ying
    Staff
    Customer Support
    #2275069
    Adarsha

    That worked. Thank you

    #2275104
    Adarsha

    While I’m at this, can I deactivate snippets plugin? I have 2 php codes added through it. (Enabled in it)
    Should I keep the plugin active all the time?

    #2275136
    Ying
    Staff
    Customer Support

    Yes, you’ll need to keep the plugin activate all the time as long as you need the PHP snippet.

    #2275143
    Adarsha

    Alright, thank you ๐Ÿ™‚

    #2275173
    Ying
    Staff
    Customer Support

    No problem ๐Ÿ™‚

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.