New answers tagged

1

Use array_diff() to remove the current post ID from an array of other post IDs. $include = array( 17, 111, 108, 158); $include = array_diff( $include, array( $post->ID ) ); $args = array( 'post__in' => $include ); $posts = new WP_Query( $args ); Edit to include a point raised by Pieter Goosen--If $include is not a hard-coded array of IDs but ...


1

Here's an approach similar to what @Milo suggests. Let's say we have: $tags = wp_get_post_tags( 123 ); If we need to filter out the term with term_id 15, we can use wp_list_filter: $_tags = wp_list_filter( $tags, [ 'term_id' => 15 ], 'NOT' ); where the NOT is the operator for excluding it. If we also need to pluck out a single attribute we can ...


1

METHOD 1 - wp_get_post_terms() We can make use of the wpse_exclude parameter to exclude and array of terms from the list of post terms. wp_get_post_tags() internally uses wp_get_post_terms() which uses wp_get_object_terms(). When looking at the source of the latter, we see that we can make use of the wp_get_object_terms filter to filter the output from the ...


4

In addition to the answer by Tim, one can always use a proper tax_query. All the build in tag and category parameters gets converted to a proper tax_query before being passed to the WP_Tax_Query class to build the JOIN clause for the SQL query. I use a tax_query in almost all applications as it gives one a lot of flexibilty, specially when it comes to child ...


4

From a quick look at the documentation for get_posts(), it doesn't look like you can exclude a post based on its category. EDIT: Actually, thanks to AntonChanning, turns out you can - just add &cat=-1 to your argument string, where 1 is the ID of the category you wish to exclude: $postslist = get_posts('numberposts=1&order=DESC&orderby=date&...



Top 50 recent answers are included