• Resolved Bam Bam

    (@bam-bam)


    Hi,

    Just discovered this plugin, great for people like me that struggle with PHP and Javascript.

    I just created a Post Grid block and I’m wondering if it is possible to hard code an exclusion into it ??

    What I want to exclude is a sticky post from the grid and display it normally above the grid.

    Kindest Regards
    Bam Bam

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Luke Carbis

    (@lukecarbis)

    Hi @bam-bam. Assuming you’re using WP_Query to build your posts grid, you can specify a post ID as part of the post__not_in parameter.

    For example:

    
    $exclude = array( 42 );
    $query = new WP_Query( array( 'post__not_in' => $exclude ) );
    
    Thread Starter Bam Bam

    (@bam-bam)

    Thanks for the prompt reply, I’m using all of the code from one of your tutorial pages.

    PHP and Javascript does my head in, just where and exactly in that query should I add post id ??

    The post ID is 438.

    Also just where should I place the code in the file ??

    Sorry to be such a numpty, but I’m getting old and have my head around HTML and CSS but the rest is like Hieroglyphics to me.

    • This reply was modified 4 years, 8 months ago by Bam Bam.
    Plugin Author Luke Carbis

    (@lukecarbis)

    Assuming your using the code from this post: https://getblocklab.com/custom-post-grid-block-using-wp_query/

    Modify the part that is commented as “WP_Query Arguments” to add the exclude:

    
        // WP_Query arguments
        $args = array(
            'post_type'      => array( $post_type ),
            'posts_per_page' => $post_count,
            'post__not_in'   => array( 438 ),
        );
    
    Thread Starter Bam Bam

    (@bam-bam)

    Many thanks, worked a treat, I tried all sorts of things and nothing worked.

    I did manage to hide it using some CSS but I’d rather do it this way.

    If it’s not too much to ask, how can I now show that post we just excluded, immediately above the grid on it’s own, it is a Welcome post and I was trying to make it prominent, it is tagged as a Sticky post if that helps.

    Like it displays on the Blog page that is already there.

    https://healthut.com/blog-posts/

    Many thanks for your help on this.

    Kindest Regards
    Bam Bam

    Plugin Author Luke Carbis

    (@lukecarbis)

    One way would be to reuse the same code again, but this time change post__not_in to post__in.

    Thread Starter Bam Bam

    (@bam-bam)

    Ok thanks I’ll give it a whirl

    Thread Starter Bam Bam

    (@bam-bam)

    @lukecarbis Thanks for your help with this, but I messed about with it for ages and couldn’t get it working, so I just made a duplication of the original block and made a couple of changes to it and I got exactly what I was after.

    Great plugin.

    Kindest Regards
    Bam Bam

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding exclusions to a block’ is closed to new replies.