Proper way to update the slug of a taxonomy using register_taxonomy? [duplicate]

register_taxonomy triggers the action registered_taxonomy immediately after it’s registered, which gives you the arguments it was registered with. As long as the taxonomy key doesn’t change, you can hook that action, modify the arguments, then re-register it. function wpd_update_taxonomy_args( $taxonomy, $object_type, $args ){ if( ‘plugin_tax’ == $taxonomy ){ // remove this action so we don’t … Read more

Using custom taxonomies in a query

I looked at the source code for IssueM. I think the slug you are after is issuem_issue However, there are two more taxonomies it registers: issuem_issue_categories and issuem_issue_tags Edit Try changing your args to: $args = array( ‘post_type’ => ‘article’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘issuem_issue’, ‘field’ => ‘slug’, ‘terms’ => ‘issue-one’ ), ), … Read more

Custom post type – list posts based on meta_key and display them divided by CPT taxonomy category

Here’s the code, rewriten from posts and categories to custom post types and taxonomy terms. Thanks to @PieterGoosen for providing the first version. http://pastebin.com/xKBepGQz <?php $args = array( ‘post_type’ => ‘produkty’, // your CTP name ‘meta_key’ => ‘produkt_nowosc’, // custom meta key for displaying, in my case: the newest product in offer ‘meta_value’ => ‘tak’, … Read more

How does the ‘the_post_navigation()’ work for CPT’s?

‘the_post_navigation’. It seems to work for Custom Post Types (CPTs) but I cannot figure out how it does this. the_post_navigation() uses get_the_post_navigation() which uses get_previous_post_link() and get_next_post_link() which both uses get_adjacent_post_link() which uses get_adjacent_post() to get the next and previous post from the same post type. If we look at the source code for get_adjacent_post(), … Read more

Hide specific taxonomies from a taxonomy list using ‘get_object_taxonomies’

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( ‘taxonomy’ => $taxonomy->name, ‘hide_empty’ => true, ) ); if ( ! empty( $terms … Read more

Foreach inside foreach

First, I’d extract all the slugs of the recommended colour terms with something like this: $recommended_colours = wp_get_post_terms($post->ID, ‘recommended_colours’); $recommended_colour_slugs = array_map(function($colour) { return $colour->slug; }, $recommended_colours); … which leaves you with a $recommended_colour_slugs array that looks like this [‘blue’, ‘green’]. Then you can loop over your colour terms and use an if-else to check … Read more

Include WooCommerce product to all child categories

(1) Paste below code to your functions.php file function my_enqueue() { wp_enqueue_script( ‘my_custom_script’, get_template_directory_uri() . ‘/js/myscript.js’ ); } add_action( ‘admin_enqueue_scripts’, ‘my_enqueue’ ); (2) Create myscript.js file and paste below code in it and place the file in ‘yourtheme/js/’ folder. jQuery(document).ready(function () { jQuery(‘#categorychecklist’).prepend(‘<input type=”checkbox” id=”selectall”><label for=”selectall”>Select all subcategories.</label><hr>’); jQuery(‘#categorychecklist [type=”checkbox”]:not(#selectall)’).on(‘change’, function () { if(jQuery(‘#selectall’).is(‘:checked’)) { … Read more