New answers tagged

0

I'm assuming that you don't want to set different labels for these taxonomies in the first place - you didn't specifically mention that you can't, but I'm assuming the thought occurred to you. Just in case it didn't, from your code: register_taxonomy("product_cat", "product", array( "labels" => array( "name" => "Categories", Changing "...


0

Just use the slug component of your rewrite argument for your custom taxonomy: register_taxonomy([ 'rewrite' => [ 'with_front' => false, 'slug' => 'cpt', ], // Other args ]);


0

If I understand you correctly, you're basically wanting to grab one post from each taxonomy term. And then get that post's link. WP_Query is your friend here - with a custom query, you can get posts with almost any criteria you want (check the docs I've linked to there, they outline almost everything you can do). The criteria in this circumstance is a ...


0

The Codex says: term_id is the ID of a term in the terms table term_taxonomy_id is a unique ID for the term+taxonomy pair What does this mean? A term is a word. It can belong to a taxonomy, such as tags, categories, or a custom taxonomy. The thing is: there can be several taxonomies containing the same term. Let’s say you have a term called “fattening“....


0

As this is a part of a bigger understanding of the design I will describe it as whole... :) In WP 4.5.3 there are still all these tables (I will talk about them without prefix): posts term_relationships term_taxonomy terms The path to get post terms' readable names goes through them all. posts the main identificator here is ID - an id of a post (of any ...


0

I'd set up... Teams and Tournaments as taxonomies Players and Managers as post types. If you link the taxonomies to both post types you will be able to link both Players and Managers to the same Team or Tournament. CPT UI is a pretty good plugin to help create and manage custom post types.


1

For reliability, you can get the current term being viewed from the queried object from $GLOBALS['wp_the_query'] $current_term = sanitize_term( $GLOBALS['wp_the_query']->get_queried_object() ); To answer your question, if Southern Africa is top level, it should have a parent term ID of 0. All child terms should have a numeric value as parent which ...


1

You need to use %cities% (matching the name of the taxonomy). I thought that %city% was just a placeholder with a random name. Not quite - it's called a permalink structure (permastruct) and is used to map to a regular expression. When you call register_taxonomy, it automatically registers a new permastruct with the same name as the taxonomy. Read up ...


0

Use WP set object terms $new_post = array( 'post_title' => $title, 'post_content' => $description, 'tags_input' => array($tags), 'post_address' => array($address), 'post_status' => 'draft', // Choose: publish, preview, future, draft, etc. 'post_type' => 'trademen' //'...


4

There are e.g. the following dynamic sanitize_term_fields() filters: edit_term_{$field} filter for the edit context pre_term_{$field} filter for the the db context term_{$field}_rss filter for the the rss context term_{$field} filter (default) and also the taxonomy-specific ones: edit_{$taxonomy}_{$field} filter for the edit context pre_{$taxonomy}_{$...


3

Looking at the files that create the metabox, there isn't anything to really hook into that will allow us to add the description so we'll need to use jQuery. Since the script is extremely small, I've opted not to put it into an external file but instead use the admin_footer hook: /** * Prepend taxonomy descriptions to taxonomy metaboxes */ function ...


0

You can easily just get the taxonomies you need with wp_get_object_terms, and than do something like $class =''; foreach ($genres as $genre) { $class .= $genre->slug; } Do this for each of your taxonomies,than just echo $class.


1

As of WP 3.7 (https://core.trac.wordpress.org/ticket/14206) you can add this argument to register_taxonomy: 'meta_box_cb' => 'post_categories_meta_box' to get the built-in checkbox category style metabox without having to make your taxonomy hierarchical. Also you could instead provide your own callback function to create your own metabox (i.e. with a ...


0

Without seeing the code, it's a bit hard... But if you're trying to query for a certain taxonomy when 'post_type' => 'page', make sure you Add a registered Taxonomy to a registered Post Type. (See Codex) In this case, you would add it to 'post_type' => 'page' since "Pages" do not support any taxonomies by default. Again, you may have done this ...


0

If you want the terms ordered by slug rather than name then use this... <?php if(has_term('', 'CUSTOM-TAX')) {?> <?php $custom_terms = get_the_terms( get_the_ID(), 'CUSTOM-TAX' ); // Make sure we have terms and also check for WP_Error object if ( $product_terms && !is_wp_error( $product_terms ) ) { @usort( $...


0

WordPress is generating the tax query for you - when you register a custom taxonomy, it also registers what's known as a query var. This is a "key"-type value that means you can simply do this: new WP_Query([ 'age_from' => 2 ]); ... and WP will transform that to: WP_Tax_Query([ [ 'taxonomy' => 'age_from', 'terms' => 2, ...


0

With the get_term_children() function there is nothing to pass which will hide empty terms. You could do that in your foreach as each term has a property which holds how many posts it is assigned: foreach( $style_categories as $style ) { $child = get_term_by( 'id', $style, 'product_cat' ); // Skip empty terms if( $child->count <= 0 ) { ...


0

'LIKE' isn't supported by the current version of WP_Tax_Query, so you'll need to write a custom query. This answer from a couple of years ago still seems to be the best approach: http://wordpress.stackexchange.com/a/133805/26317.


0

I eventually managed to find a solution: First of all, the pre_get_posts action that I originally had wasn't good, because both the events and the posts are displayed using the same template (taxonomy-event-category.php). The code that I wrote in pre_get_posts forced wordpress to display only events in that template, so I removed it. I replaced it with ...


3

Maybe try wp_insert_term once the plugin has been enabled: https://codex.wordpress.org/Function_Reference/wp_insert_term I.e. wp_insert_term( 'Male', // the term 'dog_sex', // the taxonomy array( 'slug' => 'male', ) );


1

Something like this should work, where series is the taxonomy name and not a option within a taxonomy: $args = array( 'post_type' => 'my_post_type', 'tax_query' => array( array( 'taxonomy' => 'series', 'operator' => 'NOT_EXISTS', ), ), ); $query = new WP_Query( $args ); reference with plenty ...


0

This is the finish code for this: <?php $dates_array = array(); $countries_array = array(); $term_list = array(); $current_term_list = array(); $args = array( 'post_type' => 'tours', 'posts_per_page' => -1 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); global $post; ...


2

You're using the same slug for both your videos custom post type and video_type taxonomy. Then, when querying post, WordPress don't know what to select from database. Change your videos post type to video or something differs from videos taxonomy slug will solve your problem.


1

You could try unsetting the original search query, otherwise you may be doubling up and the combination results in nothing? eg, try adding to your function: $query->set('s',''); UPDATE I am not sure on this one, but you could try the AND operator -I think this adds to the existing query instead of replacing it... function mytheme_pre_get_posts( $...


0

as long as the slugs from your articles taxonomy map exactly to the slugs in your default category you should be able to do something like this for each article: $article_cats = wp_get_object_terms( $article_id, 'article-category' ); $new_cats = array(); foreach( $article_cats AS $t ) { $new_cats[] = $t->slug; }...



Top 50 recent answers are included