New answers tagged

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

Personally, whenever I register a taxonomy which I will use its fixed terms to query contents, I often disallow user to enter terms' slugs manually. Admin will add all terms with predictable terms' slugs. Then, users will choose from that term list. It help me a lot when managing terms table. To archive it, I always use a very nice built-in feature: Choose ...


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


0

Custom template should be archive-gallery.php instead of archive-posttype.php It's archive-$posttype.php where $posttype is the custom post type slug. WordPress first looks for archive-$posttype.php and if it's not available then chooses archive.php Update Same for the custom taxonomies also , the flow is: taxonomy-$taxonomy-$term.php --> ...


0

@darrinb I have solved the problem. Your code helped me a lot although had a error. :) The error was getting the 'terms': $terms = get_terms( array( 'taxonomy' => $taxonomy->name, 'hide_empty' => true, ) ); Following the codex: The correct way is the following: $arg = array( 'hide_empty' => true, ...


0

where it should be placed whether in page-template directory or at theme root directory? It should be placed at the root directory of the the active theme. If you take a look at template heirarchy, you can see that for taxonomy the flow is: taxonomy-$taxonomy-$term.php --> taxonomy-$taxonomy.php --> taxonomy.php So the correct name for term ...


0

I found an answer that works well. Using two dropdowns in a 'cascading' style, with the code in the gist below, users would pick from a list of parent terms first, then a second dropdown appears with the list of children. The key is that both the parent and the child terms are 'selected'. Just took a bit of tweaking to get it right, but it seems to work ...


1

Try this: <?php $object = 'post'; $output = 'objects'; $taxonomies = get_object_taxonomies( $object, $output ); $exclude = array( 'post_tag', 'post_format' ); if ( $taxonomies ) { foreach ( $taxonomies as $taxonomy ) { if( in_array( $taxonomy->name, $exclude ) ) { continue; } $terms = get_terms( array( ...


0

Go to Settings/permalinks and click save. To prevent this from being a problem with plugins, or themes that insatiate CPT's/ Taxonomies there is the function flush_rewrite_rules. here is the link from the codex.


0

Just use strip_tags <?php echo strip_tags(get_the_term_list( $post->ID, 'CUSTOM-TAXONOMY', ' ',', ')); ?>


0

If you want the taxonomy under products post type then you must change your code from. register_taxonomy( 'manufactures', 'manufactures', array( 'hierarchical' => true, 'labels' => $labels, 'query_var' => true, 'show_admin_column' => false, 'show_ui' => true ) ); to register_taxonomy( ...


0

So, what you are trying is to add manufactures taxonomy for product post type of Woocommerce Plugin? Change manufactures object type to product and it should work. register_taxonomy( 'manufactures', 'product', array( 'hierarchical' => true, 'labels' => $labels, 'query_var' => true, 'show_admin_column' ...


0

Here what I did & finally problem is solved. To make the code work just use get_term_meta and add true to be like this: $res .= get_term_meta($t_id,'publication_date',true); I hope this will help any one facing such issue. Also, those who use prefix need to add it before the field name as mentioned by P-S


1

Possible solutions: Check if there's a prefix which you setup for the custom field (https://en.bainternet.info/tax-meta-class-faq/#comment-1107) Go to the Tax-meta-class/Tax-meta-class.php file and find the function you're calling and debug the issue: // Tax-meta-class.php public function get_tax_meta($term_id,$key,$multi = false){ $t_id = ...


0

For the archive by the term, you should go with taxonomy template. For you it will be taxonomy-project.php When you work with custom post type , you should update the permalink structure when you make changes on templates, I mean register new post type or create new template file


0

You cannot have a rewrite slug of '/'. Note that using a slug of '', which you will find floating around, will not work for the latest WordPress versions either. If you want a url like http://domain.com/custom-post, there are no bullet-proof solutions, but the answer to this question will give you some leads: Remove slug from custom post type post URLs


0

You can use wp_list_categories() and pass in your custom taxonomy as an argument like so: $args = array( 'taxonomy' => 'locations', 'orderby' => 'name', 'hide_empty' => false, 'show_count' => false, 'pad_counts' => false, 'hierarchical' => true, 'title_li' => '' ); ?> <ul> ...


0

Here is a better solution that will not change anything in your post, but will only add a meta // Set the post language when loading up the page based on the store meta function ppl_set_post_language() { $postID = url_to_postid( $_SERVER["REQUEST_URI"] ); if ($postID > 0) { $postLanguage = esc_attr( get_post_meta( $postID, ...


0

You can get the terms and then create an array of term ids which you pass as include parameter to get terms with menu order parameter and woocommerce will handle the rest like this: $terms = get_the_terms($post->ID, 'product_highlights'); if (!empty($terms) && is_array($terms)) { $post_terms = array(); foreach ($terms as $term) { ...


0

By default, all public post types are included in the main main query on taxonomy pages. If you look at register_post_type()'spublic parameter when set to true 'true' Implies exclude_from_search: false, publicly_queryable: true, show_in_nav_menus: true, and show_ui:true. When you register your post type, you set exclude_from_search to true. ...


5

If I am understanding you have a taxonomy that is shared across multiple post types? And you want to make a custom template for each post type using the Wordpress's templating system. Which isn't possible. What you could do is add conditionals to your taxonomy-disrupt-categories.php to check what the current post type is and load different template parts ...


0

I've checked another option and asigned my custom taxonomy to custom post type using its name but without capitals and space. 'postname' works with original 'Post Name' So for custom post type register_post_type( 'Post Name', $args ); I can use register_taxonomy( 'custom taxonomy', array( 'postname' ), $args ); And it works.


0

@TJ Sherrill, as alternative of @Milo answer, WordPress say, "If you want to alter the value of an option during the rendering of a page without changing it permanently in the database you can use pre_option_(option name). Here the sample code related to your issue, using is_tax as conditional taxonomy: add_filter( 'pre_option_posts_per_page', ...


1

Use the pre_get_posts action to modify query parameters before the queries are run. You can use many of the Conditional Tags to target specific types of pages. function wpd_alter_posts_per_page( $query ) { // don't alter admin or custom queries if ( is_admin() || ! $query->is_main_query() ) return; // if this is your-custom-tax ...


0

You'e not echoing out $cat in your foreach loop in the code you provided. Change : <li><?php $cat; ?></li> to <li><?php echo $cat; ?></li> Edit: get_terms() returns an array of objects. So if you want to display the name of the term in your foreach loop it would be: <li><?php echo $cat->name; ...


1

As noted in the comments, Labels appears to be a taxonomy, not a post type (which is why your code snippet didn't work. Probably the easiest way to get to do this is using get_the_term_list() like so: echo get_the_term_list( get_the_id(), 'labels', '', ', ', '' ); That snippet assumes two things: That it's used in the loop. That "labels" is the correct ...


0

As said in the comments by Milo (many thanks!) the answer was already posted: Permalinks: custom post type -> custom taxonomy -> post


0

If custom taxonomy makes sense to you as approach to organization of data, but not as interface workflow then you should consider building custom interface for it. Some frameworks out there can work with native taxonomies, but provide alternate interfaces for them. So you might even find something fitting already done. The more low key approach I can ...



Top 50 recent answers are included