New answers tagged

0

I also have right now same issue. This is not a bug. Ex. If you want to filter 2 different 'custom post type' example 'bed_post' and 'chair_post' by taxonomy 'metal' you can use same name for them. If not use different name. Remember that you can use same slug with different taxonomy name. $furniture->register_taxonomy(array( 'taxonomy_name' => ...


0

You need to use the methods of your query instance, rather than the global functions (which are merely wrappers for the global $wp_query): if ( $query->have_posts() ) { $term = $query->queried_object; while ( $query->have_posts() ) : $query->the_post(); //Output my posts the_title(); the_content(); endwhile; ...


2

WordPress will cache all terms for taxonomies attached to all post types in the query result set by default - well, so long as you haven't set either cache_results or update_post_term_cache to false (codex). So calling get_the_terms etc. within the loop will not hit the database. However, wp_get_object_terms will hit the database as it by-passes WordPress' ...


0

If you just need IDs, get_ancestors will return an array of parents for any type of object: $term_id = 21; $ancestors = get_ancestors( $term_id, 'location' );


0

Example for the answer of goldenapples: $update_taxonomy = 'my_taxonomy'; $get_terms_args = array( 'taxonomy' => $update_taxonomy, 'fields' => 'ids', 'hide_empty' => false, ); $update_terms = get_terms($get_terms_args); wp_update_term_count_now($update_terms, $update_taxonomy);


0

Update - Creating a class that mimics WP_Terms and copying over the objects returned by get_the_terms() to my *_Terms class worked. Passing in the returned objects when instantiating my class hits the constructor and builds out a copy of the properties that I have control over without worrying about core code changes: $categoryTerms = ...


1

I suggest post status transitions that runs only when your set conditions are met. Example: add_action( 'transition_post_status', 'add_awesome_terms', 10, 3 ); function add_awesome_terms( $new_status, $old_status, $post ) { // only run when it's a page, new status is publish and old status isn't publish if ( $post->post_type == 'page' ...


1

The idea here would be to use the queried object's ID to get the post terms (because we are most probably outside the loop here, if inside the loop, just use get_the_ID()). From there, we can use wp_list_pluck() to get all the term ID's and simply pass that to get_terms() exclude parameter Just a note, as from WordPress V4.5, the taxonomy should be passed ...


0

First you will need an array that contains all categories of the current post: $current_cats = wp_get_post_categories(); // assuming you are in the loop Then you have to loop through $current_cats and remove the items from $terms foreach( $current_cats as $cat ) { if (($key = array_search($cat, $terms)) !== false) { ...


3

Your original solution was a hack, and no surprise it failed. In general never add methods/attributes to objects that you do not control their class and future development. The right way is to create your own object to be passed to the walker. Pass to it the category object on construction and either populate fields is a similar way to the category object ...


0

I used this script to select a category using jQuery. Inside wp-admin/post-new.php $category_name_check = "My Category Name"; echo "<script type=\"text/javascript\">"; echo "jQuery( \"label:contains('$category_name_check') > input\" ).attr('checked', true)"; echo "</script>"; where $category_name_check is the name of the category to be ...


2

To do that, you'll need a custom query - Wordpress doesn't have a ready-made function for getting that type of data from the termmeta table. The custom query uses get_col() which allows you to get an array of the term_ids where the meta_key and the meta_value match the values you have in the question. Notice that the query uses prepare() which is good ...


0

WordPress tracks which object types taxonomy applies to. This can be established on taxonomy registration or at some point after, so you shouldn't be trying to do this too early. The approach would be to retrieve the list of taxonomies for the native post type and use it with lower level function, which supports multiple taxonomies: $terms = ...


2

On the top of my head there are two easy ways to go about this problem, first is to use the get_the_tags() function to manually loop the tags to easily insert the hashtags. $tags = get_the_tags(); if ( $tags ) { foreach ( $tags as $tag ) { ?> <a href="<?php echo get_tag_link( $tag->id ); ?>"> <?php echo '#' ...



Top 50 recent answers are included