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; ?>
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
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”);
How about passing the smallest and largest arguments to wp_tag_cloud() and making them both the same? <?php wp_tag_cloud( array( ‘taxonomy’ => ‘channels’, ‘smallest’ => ‘1’, ‘largest’ => ‘1’, ‘unit’ => ’em’, ) );?> Update: use get_terms() to get multiple taxonomy terms: <?php $terms = get_terms(array(‘channels’, ‘stations’)); if (is_array($terms)) : ?> <ol> <?php foreach ($terms as … Read more
You can use the standard WordPress function, get the dropdown already formatted and solve both problems at once. Like so: define( ‘WP_USE_THEMES’, false ); require( ‘./wp-load.php’ ); wp_dropdown_categories( array( ‘child_of’ => 0, ‘class’ => ‘postform’, ‘depth’ => 0, ‘echo’ => 1, ‘exclude’ => ”, ‘hide_empty’ => false, ‘hide_if_empty’ => false, ‘hierarchical’ => true, ‘id’ => … Read more
I recently talked about this at a couple of WordCamps. Here’s my talk from WC Portland, and the slides, source code, etc. Check out Recipe #2 specifically. First off, you should probably have a static prefix to start the URLs. It’s not 100% necessary, but without it your rewrite will conflict with page permalinks. If … Read more
What about: $taxName = “tvr_amenity”; $terms = get_terms($taxName,array(‘parent’ => 0)); foreach($terms as $term) { echo ‘<a href=”‘.get_term_link($term->slug,$taxName).'”>’.$term->name.'</a>’; $term_children = get_term_children($term->term_id,$taxName); echo ‘<ul>’; foreach($term_children as $term_child_id) { $term_child = get_term_by(‘id’,$term_child_id,$taxName); echo ‘<li><a href=”‘ . get_term_link( $term_child->name, $taxName ) . ‘”>’ . $term_child->name . ‘</a></li>’; } echo ‘</ul>’; }
Don’t run a new query in the template, modify the main query before it’s run via the pre_get_posts action in the theme’s functions.php file. function wpd_author_query( $query ) { if ( $query->is_author() && $query->is_main_query() ) { // your code to set $current_user_name here $query->set( ‘meta_key’, ‘_writer_relation_added_date_’ . $current_user_name ); $query->set( ‘orderby’, ‘meta_value_num’ ); $tax_query = … Read more