register_rest_field for custom taxonomy fields that are assosiated with custom post type

Both callbacks in the register_rest_field_for_custom_taxonomy_location() function are misspelled. change ‘get_callback’ => ‘location_get_term_meta’, ‘update_callback’ => ‘location_update_term_meta’, to ‘get_callback’ => ‘location_get_term_meta_field’, ‘update_callback’ => ‘location_update_term_meta_field’, Register Code function register_rest_field_for_custom_taxonomy_location() { register_rest_field( ‘location’, ‘location_code’, array( ‘get_callback’ => ‘location_get_term_meta_field’, ‘update_callback’ => ‘location_update_term_meta_field’, ‘schema’ => null, ) );

Post tags saving as both tag name & tag ID on post update when tags are displayed as checkboxes

Faced this problem too. You can solve it adding to functions.php filtering code: add_action( ‘admin_init’, function() { if( isset( $_POST[‘tax_input’] ) && is_array( $_POST[‘tax_input’] ) ) { $new_tax_input = array(); foreach( $_POST[‘tax_input’] as $tax => $terms) { if( is_array( $terms ) ) { $taxonomy = get_taxonomy( $tax ); if( !$taxonomy->hierarchical ) { $terms = array_map( … Read more

Get terms of posts with category with sql

Here’s the solution: global $wpdb; $wpdb->get_results( $wpdb->prepare( “SELECT tags.*, COUNT(tags_rel.object_id) as posts_count FROM {$wpdb->prefix}terms tags INNER JOIN {$wpdb->prefix}term_taxonomy tags_tax ON (tags_tax.term_id = tags.term_id) INNER JOIN {$wpdb->prefix}term_relationships tags_rel ON (tags_tax.term_taxonomy_id = tags_rel.term_taxonomy_id) INNER JOIN {$wpdb->prefix}posts posts ON (tags_rel.object_id = posts.ID) INNER JOIN {$wpdb->prefix}term_relationships cats_rel ON (posts.ID = cats_rel.object_id) INNER JOIN {$wpdb->prefix}term_taxonomy cats_tax ON (cats_rel.term_taxonomy_id = cats_tax.term_taxonomy_id) … Read more

Nice URLs for a Custom Post Type List with a Shared Custom Taxonomy?

For the first preference, you’d need to filter in additional rewrite rules like so; function __extra_country_rewrite_rules( $rules ) { global $wp_rewrite; if ( !isset( $wp_rewrite ) ) $wp_rewrite = new WP_Rewrite; $m1 = $wp_rewrite->preg_index(1); // preg match backreferences $m2 = $wp_rewrite->preg_index(2); $m3 = $wp_rewrite->preg_index(3); $rules[‘country/([^/]+)/([^/]+)s/feed/(feed|rdf|rss|rss2|atom)/?$’] = “index.php?country=$m1&post_type=$m2&feed=$m3”; $rules[‘country/([^/]+)/([^/]+)s/(feed|rdf|rss|rss2|atom)/?$’] = “index.php?country=$m1&post_type=$m2&feed=$m3”; $rules[‘country/([^/]+)/([^/]+)s/page/?([0-9]{1,})/?$’] = “index.php?country=$m1&post_type=$m2&paged=$m3”; $rules[‘country/([^/]+)/([^/]+)s/?$’] = … Read more

How can I set a default listing order on the admin page for a custom taxonomy? (without plugins)

You need to take a look at /core_root/wp-admin/includes/class-wp-terms-list-table.php and then add an extended class and make use of the WP_list_Table Class and documentation. basically you’re overriding the order and orderby in some custom plugin. Btw: “No Plugins” is never a good idea as plugins may show you how it works in code and therefore be … Read more

How to assign default taxonomy to pages on ‘save_post’?

You are using wp_set_object_terms wrong, the second parameter should be the term slug or id and the 3 parameter should be the taxonomy name, so try: function set_default_object_terms( $id, $post ) { if ( ‘publish’ === $post->post_status ) { log_me (‘be in function while “publish” i pressed with this id: ‘.$id); $taxonomy_ar = get_terms( ‘property-features’ … Read more

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