Tag Info

New answers tagged

0

What do you mean by "dynamic" ? Do you want it to work with different posts? If so, that's simple. Before your get_posts query function, get page terms, and pass them to your array. You can get taxonomies with <?php get_the_terms( $yourpostid, 'your_custom_taxonomy'); ?>


0

You might try leveraging get_term_children to generate an array of all the children of that taxonomy, and then check against empty(). Since it returns an empty array, you should be able to do something like this: (You'll need to find out your term's id, which is a number, and replace it in the below $term_id variable) $term_id = 2 $taxonomy_name = ...


2

The get_term_children function should help here. This returns an array, either with the child terms inside it, or empty. Checking if this array is truthy or not as you loop through will then let you determine whether or not to add the class. <?php $terms = get_terms('wpsc_product_category'); if ( !empty( $terms ) && !is_wp_error( $terms ...


0

Thanks for your help! I've made some small adjustments and I got it working now: <?php // your taxonomy name $tax = 'cat'; // get the terms of taxonomy $terms = get_terms( $tax, $args = array( 'hide_empty' => false, // do not hide empty terms )); // loop through all terms foreach( $terms as $term ) { // Get the term link $term_link = ...


0

I didn't understood your question well, but try this. Explanation is in the comments. // your taxonomy name $tax = 'post_tag'; // get the terms of taxonomy $terms = get_terms( $tax, [ 'hide_empty' => false, // do not hide empty terms ]); // loop through all terms foreach( $terms as $term ) { // if no entries attached to the term if( 0 == ...


1

I had the same problem and I solved easily. Check this out: Define $taxonomy. It can be the slug of the taxonomy you want to get the data. After doing this, you can simply do this: <?php $postterms = wp_get_post_terms($post->ID, $taxonomy); // get post terms $parentId = $postterms[0]->parent; // get parent term ID ...


1

As I said, this is doable, but we need to do careful planning as this is quite a heavy operation. On my test installation with a post count of just 13 posts, and 3 terms per taxonomy, the db is visited 20 times and the complete operation takes 0.03613 seconds. I have tried a couple of solutions, and this one is by far the fastest. We will look at a ...



Top 50 recent answers are included