Get random out from get_terms()
Get random out from get_terms()
Get random out from get_terms()
Unset actions for terms parent only
That’s easy, instead of trying to change which template gets loaded, load the single-grants.php template, then use get_template_part inside it, and pass different values based on the terms the post has. Be careful though, single-termname.php is not a good naming scheme, as it could be abused, e.g. you could encounter clashes. It would be better … Read more
Could you not just keep the same taxonomy and declare it on both CPTs?? That way both would inherit the same terms, at the same IDs, which would allow you to get posts from both CPTs if required. At your CPT creation, you can tell it which Taxonomies to use by setting a parameter of: … Read more
user2660802 reports that the problem has been resolved thanks to using Pieter Goosen’s suggestion of using pre_get_posts instead of query_posts(). query_posts() breaks the main query, it is slow, and totally stuffs up pagination.
The quick take would be something like this: $categories = [ ]; $parent_categories = get_categories( [ ‘parent’ => 0 ] ); foreach ( $parent_categories as $parent_category ) { $id = $parent_category->term_id; $categories[ $id ] = wp_list_pluck( get_categories( [ ‘parent’ => $id ] ), ‘term_id’ ); } The important bit is a parent argument, which limits … Read more
You could use get_terms() and loop through it – using the term description as the “short name” and slug as the specific class ( or you could use an array of colors of your choice ). Let’s look at a quick example: <?php $terms = wp_get_post_terms( $post_id, ‘category’ ); if( ! empty( $terms ) ) … Read more
User gmazzap has a good explanation of Object Cache you may want to read over. If we take a look at get_terms() we can see it creates a new WP_Term_Query() and that classes get_terms() is where the potential caching happens. Line 666 specifically. Just a little further down we can see if it test if … Read more
So here’s some info for any other people with this issue. get_terms will not use the number parameter under certain conditions, such as if you pass in a parent parameter or if the hierarchical parameter is true. In these cases I have tried two workarounds, neither very good. You can call get_terms then do an … Read more
I found the answer CSS Tricks and it works. Here’s the code I use. $terms = get_the_terms( $post->ID , ‘portfolio_user’ ); foreach ( $terms as $term ) { echo $term->slug; }