Add taxonomy to already registered custom post type
You want to use the register_taxonomy_for_object_type function documented here add_action(‘init’,’fix_my_tax’); function fix_my_tax(){ register_taxonomy_for_object_type(‘taxonomy’, ‘post_type’); }
You want to use the register_taxonomy_for_object_type function documented here add_action(‘init’,’fix_my_tax’); function fix_my_tax(){ register_taxonomy_for_object_type(‘taxonomy’, ‘post_type’); }
Using your current code: $tax_slug = get_query_var( ‘event-categories’ );
To be really honest here, that is a useless parameter when used with custom taxonomies, as custom taxonomies are already registed to a custom post type when they are registered. Using the taxonomies parameter, you are re-registering a custom taxonomy to the custom post type As stated by the codex, the taxonomies parameter is used … Read more
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 … Read more
You can update a posts type using wp_update_post: $my_post = array( ‘ID’ => $post_id, ‘post_type’ => ‘winner’, ); wp_update_post( $my_post, true ); // check if it failed and tell the user why if ( is_wp_error( $post_id ) ) { $errors = $post_id->get_error_messages(); foreach ( $errors as $error ) { echo ‘error: ‘.esc_html( $error ); } … Read more
I think you need an update_callback in register_rest_field(). Please note that I haven’t tested this. add_action( ‘rest_api_init’, ‘slug_register_meta’ ); function slug_register_meta() { register_rest_field( ‘place’, ‘meta’, array( ‘get_callback’ => ‘slug_get_meta’, ‘update_callback’ => ‘slug_update_meta’, ‘schema’ => null, ) ); } function slug_get_meta( $object, $field_name, $request ) { return get_term_meta( $object[ ‘id’ ] ); } function slug_update_meta($value, $object, … Read more
I think you are in the right direction. You can display all the provinces with get_terms() and display all the restraunts in that perticular province using loop-restraunt.php template. One more suggestion, you might also want to add “custom-fields” in the “supports” array of register_post_type. This will enable custom fields and will be helpful in many … Read more
The getEntityRecords() method uses the REST API, so make sure the taxonomy is enabled for the REST API. You can enable it via the show_in_rest parameter when registering the taxonomy using register_taxonomy(). With getEntityRecords(), if you set per_page to -1, it will actually be changed to 100, which as you’ve figured it out, is the … Read more
You can do something like the following: $terms = get_the_terms( $post->id, ‘genre’ ); // get an array of all the terms as objects. $terms_slugs = array(); foreach( $terms as $term ) { $terms_slugs[] = $term->slug; // save the slugs in an array }
you could modify the global variable $wp_post_types or in the case of taxonomies, $wp_taxonomies for example, this will change the menu name and all the labels for the default Posts to Bacon: function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = ‘Bacon’; $submenu[‘edit.php’][5][0] = ‘Bacon’; $submenu[‘edit.php’][10][0] = ‘Add Bacon’; $submenu[‘edit.php’][16][0] = ‘Bacon Tags’; echo ”; … Read more