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 ) );
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 5 years, 11 months ago by
Bam Bam.
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 ),
);
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
One way would be to reuse the same code again, but this time change post__not_in to post__in.
Ok thanks I’ll give it a whirl
@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