New answers tagged

2

You should be using get_the_terms(). wp_get_post_terms() queries the db to get post term info, where as get_the_terms() returns the post term objects directly from the post term cache and only queries the db if that info is not available. By default, all post's terms are cached by the query being executed. EDIT I cannot comment (crappy mobile), but there ...


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; ...


0

Assuming that you are trying to filter your terms to only show terms that either have children or not, you can actually use the childless parameter in your get_terms() function. $children = get_terms( 'taxonomy' => '$taxonomy_slug', 'hide_empty' => false, 'childless' => true ) ); This will output an array of terms that don't have ...


0

Just change 'fields' => 'name' to 'fields' => 'names' If you look at the examples in wordpress documentation you can see you should use plural(names, slugs, ids for fields): https://codex.wordpress.org/Function_Reference/wp_get_post_terms#Examples


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' );


2

In your tax_query array you need to add the keys as well as the values. So... 'tax_query' => array( array( 'taxonomy' => 'event_specific', 'field' => 'slug', 'terms' => 'main-event' ) )


1

Use get_term_children() $term_id = 2; // use get_queried_object()->term_id; to get the current term id $taxonomy_name = 'mypages'; // use use get_queried_object()->taxonomy; to get the current taxonomy name $countchildren = count (get_term_children( $term_id, $taxonomy_name )); echo $countchildren;


0

Yo might want to have a look at this post: Getting taxonomy terms used by custom post type You can include the empty terms by passing 'hide_empty' => 0,.


0

Assuming you are using a hierarchical taxonomy this worked for me, change 'tx' to whatever you called your taxonomy. Note, if WP change their HTML structure in the future or naming conventions this may not work. add_action('admin_footer', function() { ?> <script type="text/javascript"> jQuery(document).ready(function ($) { //taxonomy ...


0

I think your issue is with the rewrite portion when you registered the custom taxonomy with posts. 'rewrite' => array('slug' => 'some-slug', 'with_front' => false) You can replace some-slug with anything you would like. It might be possible to replace it with article/event-category to get the results you want. Setting with_front to false removes ...


0

I use CMB2 to set up custom fields, and the logic is not so different from ACF in many cases. For my specific use case I've created a very simple but flexible function in order to make a few checks for the taxonomy before displaying the custom field value. Considering one have created a custom field named my_cf for let's say a taxonomy named basic as per ...


2

Well, when you need to modify a theme you create a "child theme." There are good instructions for how here. So we would just create a safe copy of the modified code in a folder the other theme doesn't overwrite. What I think you want to do is create a custom post type "Book" and register this post type to a taxonomy of "Author." Here is an example: ...


1

You can wrap it in the same check used for $category: <?php if (isset($term->term_id)) { echo '<a href="'.get_term_link($term).'">'.$term->name.'</a>'; } ?> or check to make sure it is not an error object: <?php if (!is_wp_error($term)) { echo '<a href="'.get_term_link($term).'">'.$term->name.'</a>'; } ...


0

The answer was found here: http://www.wprecipes.com/how-to-display-category-name-without-link For my purposes, I needed to define the category function and then call it by name-only inside the php echo: <?php $category = get_the_category($attachment->ID); echo 'html goes here'; echo ''.$category[0]->cat_name.'; ?>


0

Herewith find the below answer for my own question for the custom taxonomies based listing the categories add_action( 'init', 'rest_custom_category_request', 25); function rest_property_type_category_request(){ global $wp_taxonomies; $wp_taxonomies['custom_category']->show_in_rest = true; $wp_taxonomies['custom_category']->rest_base = ...


0

I had a answer in development then I read what you were looking for some more. I will need more info before I can help. Is a reviewer/speaker a custom post type or a user? Is this relationship only going to be displayed on the article. Or will you also be displaying it on the Guest Authors/Speakers page as well?


0

I have added extra rewrite rules for pages with no item_width and item_height in combination with pagination as follows: /** * Adds rewrite rules for shop category */ function gtp_add_shop_rewrite_rules() { // shop-category/category/item_width/item_height/page/2/ add_rewrite_rule( '^shop-category\/([^/]*)\/([^/]*)\/([^/]*)\/page\/([0-9]*)$', ...


0

Figured it out. The Answer: // tax_query needs to be an Array of an Array 'tax_query' => array( array( 'taxonomy' => 'vodka_type', 'field' => 'slug', 'terms' => $type, ), ),


0

There's a slight catch to using bainternet's Tax Meta Class: the way you save and retrieve data changes depending on your Wordpress version. If you are using the latest version of WordPress then use get_term_meta instead of get_tax_meta. https://github.com/bainternet/Tax-Meta-Class/issues/115#issuecomment-170365995 I believe the exact ...


0

Answering own questions is becoming a habit :) But hope this helps others after finding a solution that worked for me. First defining the three variables I needed in the upload function: var features = ""; var colors = ""; var styles = ""; Then, added the following to prevent error if pwTags was empty: if (pwTags != null) { ...


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 = ...


0

In your example, the 'Key Industries' page appears to be a different page under each of those top level menus - or at the very least, the URL is different. This most likely allows their CMS to differentiate and use the correct submenu. Here's what I do when I want to achieve this: Hook into wp_nav_menu_objects and check for a custom submenu argument, ...


2

get_terms() doesn't have built-in feature that excludes draft posts because it keeps track of only total posts term is attached to. I made a quick search and found this snippet but be warned: It affects all get_terms() functions on your site (I excluded admin area) There's a SQL query in foreach loop - it will affect performance More terms returned == ...


2

The solution is to use: 'taxonomy' => 'meal', 'field' => 'slug', 'terms' => 'breakfast' The taxonomy and terms are obvious, but why does field have to be slug? When you add taxonomy parameters, you can specify what 'breakfast' is-- via the field. It could be the term's ID, the full name, or slug. See the codex on Taxonomy Parameters


0

The code that I finally came up with to fix the problem! <?php global $wpdb; $catresult = array(); $postid = get_the_ID(); $query1c = "SELECT wp_posts.ID, wp_terms.`name` AS `Category`, wp_pods_productcategory.`pc-url` AS `Url` FROM wp_posts INNER JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id INNER JOIN wp_terms ON ...


0

Instead of trying to do this through the orderby parameter, I went a different direction. Logically, the orderby parameter above only applies to the posts within each grouping, not the taxonomy term grouping itself so it won't work for this. What I ended up doing was adding 01, 02, 03, etc. to the taxonomy term name itself, then stripped that out using ...


0

There are many jQuery plugins designed specifically for this functionality. Check these ones out: http://www.jqueryrain.com/demo/jquery-multiselect-plugin/


0

As far as I remember WP core doesn't do this natively, though I think there are/were some considerations about adding select2 for tasks like this. Might be mistaken on this. However there are a lot of frameworks around, which implement additional UI for things like this. It's pretty common feature in them. I tend to use Meta Box, which should be able to do ...


0

SOLVED I found the answer in another post that was answered by @Gustav for anyone looking a solution like you can follow the link or view the code below it works perfectly. http://wordpress.stackexchange.com/questions/123059/list-post-from-current-taxonomy-children THE WORKING CODE <?php $term_slug = get_query_var( 'term' ); ...


0

If you created the taxonomy yourself, you could set your own slug for the custom taxonomy. For Example: register_taxonomy( 'productcategory', array( 'productpopups', ), array( 'labels' => array( 'name' => __('Categories', 'text-domain'), ), // --- set taxonomy slug --- 'rewrite' ...



Top 50 recent answers are included