Quantcast
Channel: User Michael - WordPress Development Stack Exchange
Viewing all articles
Browse latest Browse all 44

Answer by Michael for Remove a specific category ID from related post

$
0
0

from looking at https://developer.wordpress.org/reference/functions/wp_get_post_terms/

and https://developer.wordpress.org/reference/classes/wp_term_query/__construct/ for corresponding parameters, i.e. the 'exclude' parameter

and https://developer.wordpress.org/reference/functions/get_category_by_slug/ to get the category ids from their slugs.

it might work when you replace this line in your code:

// Get the taxonomy terms of the current page for the specified taxonomy. $terms = wp_get_post_terms( get_the_ID(), ‘category’, array( ‘fields’ => ‘ids’ ) );

with this example code:

// Get the catogory ids of the two categories to be excluded$cat1 = get_category_by_slug( 'song' ); $cat2 = get_category_by_slug( 'jpop' ); // Get the taxonomy terms of the current page for the specified taxonomy and exclude two categories$terms = wp_get_post_terms( get_the_ID(), ‘category’, array( 'exclude' => array( $cat1->term_id, $cat2->term_id ), ‘fields’ => ‘ids’ ) );

Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>