Print current post category during WP_Query

You are using the get_the_terms() but this function is used to get the custom taxonomies. Use the function get_the_category(); inside the WordPress loop and pass the get_the_ID() function which will get the current post ID in the loop. get_the_category(get_the_ID()); <?php $args = array( ‘post_type’ => ‘work’, ‘posts_per_page’ => ‘9’ ); $work_loop = new WP_Query( $args … Read more

the_terms characters not limiting

This is not working because the_terms() is echo-ing the output. It would make more sense to trim down the lengthy term names, instead of doing it directly on the HTML output of get_the_term_list() that’s used by get_the_terms(). That could give unvalid HTML, that could break the layout of your site. Here’s an example for the … Read more

Comma separated tax terms, with “and” before last item [duplicate]

This is how your code should look like I added some comments so you will understand its simple programming not really wordpress related. $locations = get_the_terms($post->ID, ‘location’); $locations = array_values($locations); $total_locations = count($locations); // the total start from 1 for($i = 0; $i < $total_locations; $i++) { echo $locations[$i]; // echo the location if($i < … Read more

Search Query for Multiple Terms In Same Taxonomy

You need to make only one change in the form, change the first line to: <select name=”property_type[]” class=”form-control” multiple> Name of the field has to include [] to be considered as an array when it arrives on the server side. In the query string it will be listed as: property_type[]=condo&property_type[]=duplex And, on server side, when … Read more

Conditional Statement with Multiple Terms?

Firstly, create some sort of association between the icon class and the term name: $icons = array( ‘webinar’ => ‘fa-desktop’, ‘report’ => ‘fa-file-text-o’, ‘video’ => ‘fa-youtube-play’, ‘past-project’ => ‘fa-cogs’, ‘meeting-material’ => ‘fa-users’, ‘info-sheet’ => ‘fa-info-circle’, ); Then loop through each term assigned to the post and output the corresponding icon: $terms = get_the_terms( get_the_ID(), ‘type’ … Read more

Count Number of Posts in Taxonomy Term in Last 24 Hours

You can create a custom WP_Query and count its result. $wp_query = new WP_Query([ ‘tax_query’ => [ [ ‘taxonomy’ => ‘news’, ‘terms’ => $term_name, ‘fields’ => ‘name’ ] ], ‘date_query’ => [ [ ‘after’ => ’24 hours ago’ ] ] ]); $number_of_posts = $wp_query->found_posts; Edit I removed posts_per_page argument, as @birgire suggests, that found_posts offers … Read more

What does wp_term_taxonomy.parent reference?

WordPress doesn’t use actual FOREIGN KEY constraints in MySQL. So, technically, wp_term_taxonomy.parent is merely an integer. However, what you’ve found is correct: it refers to a term in wp_terms by its term_id. But, as you’ve also noticed, the term_id and term_taxonomy_id should always be the same. The reason they both exists is historical. Prior to … Read more

How do I return all terms from multiple taxonomies?

You have all sorts of fun questions today! There is also a WP_Term_Query available in WordPress. Here is some info on it as well as what parameters you can pass it. https://developer.wordpress.org/reference/classes/WP_Term_Query/__construct/ $term_args = array( ‘taxonomy’ => array(‘tax_one’, ‘tax_two’, ‘tax_six’), ‘hide_empty’ => false, ‘fields’ => ‘all’, ‘count’ => true, ); $term_query = new WP_Term_Query($term_args); foreach … Read more