Create Custom Post Type Permalink Structure

The default behaviour of mysite.com/post-type/ and mysite.com/post-type/post-name/ is what you want it to be, so you don’t need to do anything special there. To have mysite.com/post-type/taxonomy/ as the URL for the taxonomy archive, all you need to do is use ‘post-type/taxonomy’ as the rewrite => slug argument when registering the taxonomy.

get_terms showing all categories instead of the ones assigned to a specific post

There are two functions: get_terms get_terms( string|array $args = array(), array $deprecated = ” ) Which retrieves the terms in a given taxonomy or list of taxonomies. And… get_the_terms get_the_terms( int|object $post, string $taxonomy ) Which retrieves the terms of the taxonomy that are attached to the post. You should use second one in your … Read more

Get Post Primary Category

Here you go. Add this to functions.php and call it from anywhere you want. function get_post_primary_category($post_id, $term=’category’, $return_all_categories=false){ $return = array(); if (class_exists(‘WPSEO_Primary_Term’)){ // Show Primary category by Yoast if it is enabled & set $wpseo_primary_term = new WPSEO_Primary_Term( $term, $post_id ); $primary_term = get_term($wpseo_primary_term->get_primary_term()); if (!is_wp_error($primary_term)){ $return[‘primary_category’] = $primary_term; } } if (empty($return[‘primary_category’]) || … Read more

How to show the category filter that’s shown on the ‘All post’ pages on a custom post type page in the admin area?

If your post type supports the category taxonomy, then that drop-down menu would be displayed by default: register_post_type( ‘my_cpt’, [ ‘public’ => true, ‘taxonomies’ => [ ‘category’ ], // here, the post type supports the `category` taxonomy //… ] ); Otherwise, or for custom taxonomies, you can use the restrict_manage_posts hook and wp_dropdown_categories() to add … Read more

Custom taxonomy is crashing Gutenberg

Changing the taxonomy name fixes. I’ll wager the guess that having it called ‘type’ was conflicting with the Gutenberg js. $args = array( ‘labels’ => $labels, ‘hierarchical’ => false, ‘public’ => true, ‘show_ui’ => true, ‘show_admin_column’ => true, ‘show_in_nav_menus’ => true, ‘show_tagcloud’ => false, ‘show_in_rest’ => true, ); register_taxonomy( ‘resource-type’, array( ‘resource’ ), $args );

Get all sub-categories of a parent category

In reply to your updated code, you should know that the $post_terms = wp_get_object_terms() would only return categories that directly attached to the post, so I’d just use wp_list_categories() to get and display the child categories for the given (or a known) parent category. And here’s the code that works well for me which displays … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)