Echo specific term in an array
It is an object, and you can use the following notation: <?php echo $myterms[0]->name; ?>
It is an object, and you can use the following notation: <?php echo $myterms[0]->name; ?>
You’re missing the tax_query key, and it needs to be a nested array: $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘terms’ => $cat_id, ‘field’ => ‘term_id’, ), ), ); Check the documentation
Try this: PHP add_action( ‘wp_ajax_my_adv_search’, ‘ajax_my_adv_search’ ); add_action( ‘wp_ajax_nopriv_my_adv_search’, ‘ajax_my_adv_search’ ); function ajax_my_adv_search() { if ( ! check_ajax_referer( ‘my-adv-search’, ‘q_nonce’, false ) ) { echo ‘session_expired’; wp_die(); } $post_type = isset( $_POST[‘q_post_type’] ) ? $_POST[‘q_post_type’] : ”; $taxonomy = isset( $_POST[‘q_taxonomy’] ) ? $_POST[‘q_taxonomy’] : []; $year = isset( $_POST[‘q_year’] ) ? $_POST[‘q_year’] : ”; … Read more
get_terms returns array of terms and not only one term, so you can’t do $terms->slug, because it makes no sense at all… If you want to display all terms, you’ll have to loop through them: $terms = get_terms( array( ‘taxonomy’ => ‘brand’, ‘hide_empty’ => 0 ) ); if ( ! is_wp_error($terms) ) { // it … Read more
Something quite rough that needs improvement but can give you a starting point, if I’ve understood your needs: use [dr] as shortcode marker where you want function my_dream_shortcode($atts, $content = null) { ob_start(); ?> <ul> <li class=”button” onClick=”get_data(‘corporate’)”>Corporate</li> <li class=”button” onClick=”get_data(‘sales’)”>Sales</li> <li class=”button” onClick=”get_data(‘support’)”>Support</li> </ul> <div class=”my_plugin_result”></div> <style> li.button{ list-style:none; padding:4px 10px; background-color:cadetblue; margin:10px; float:left; … Read more
You use the same slug publication for custom taxonomy and custom post type. Slug should be unique. Another thing (not related with 404) is the flush_rules. As you can read here flush on the init hook is bad idea. Important: Flushing the rewrite rules is an expensive operation, there are tutorials and examples that suggest … Read more
Recap: You created a custom post type = “downloads” and a custom taxonomy = “downloads_category” with a rewrite to “categoria-de-downloads” First: The “is_tax” at the head of your archive.php is failing because the name of your custom taxonomy should be “downloads_category“; it must be spelt with an underline rather than a hyphen (Codex). You also … Read more
The reason it does not show up automatically is because it requires REST enabled to display. By default, show_in_rest is set to false when registering taxonomies and post types. There’s currently a Trac Ticket #42785 open to change this default functionality. So in short when registering a taxonomy while using the Block Editor you’ll need … Read more
When you register a custom taxonomy make sure to set show_in_rest to true. This way the taxonomy will show in the REST API which is what Gutenberg uses to get the data. Then you can use the selector: wp.data.select(“core/editor”).getCurrentPostAttribute(“my_taxonomy”);
Solved by creating custom sql queries. Request for years: SELECT count(*), $wpdb->posts.id as post_id_ts, YEAR( (SELECT $wpdb->postmeta.meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.post_id = post_id_ts AND $wpdb->postmeta.meta_key = ‘docs_pubdate’)) AS years FROM $wpdb->posts WHERE $wpdb->posts.post_type=”document_base” AND $wpdb->posts.post_status=”publish” GROUP BY years which will return result like this: Array ( [0] => Array ( [count(*)] => 1 [post_id_ts] => … Read more