Use wp_set_post_terms() instead of wp_insert_post()
After some hours of further searching i found the solution: wp_set_post_terms($pid, array(“2”), “project-type”);
After some hours of further searching i found the solution: wp_set_post_terms($pid, array(“2”), “project-type”);
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.
Internally wp_list_categories() uses get_term_link() for the URL of the terms. That function can be filtered using the term_link filter, so you could filter any links to the current term and replace them with links to the post type archive: function wpse_307202_term_link( $termlink, $term, $taxonomy ) { if ( is_tax( ‘cat_projet’ ) ) { if ( … Read more
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
If I understand you correctly, then has_term should be solution for your problem… if ( has_term( ‘past-events’, ‘event_type’ ) ) { // do something }
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
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
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 );
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
You’re not running check on whether the artist’s instagram field is empty, you’re running a check on whether the ‘artists’ term is empty, which it isn’t. <?php $artistigs = get_the_terms( get_the_ID(), ‘artists’ ); if( ! empty( $artistigs ) ) : ?> //This will execute if the artist term is not empty endif; ?> I don’t … Read more