Show matching categories in search page

Essentially what you need is show the categories the current queried posts belong. I’ll post here a function that take as argument a taaxonomy (or an array of taxonomies) and return all the terms in that (those) taxonomy(ies) that are assigned to all queried posts. function queried_posts_terms( $taxonomies=”category” ) { global $wp_query, $wpdb; if ( … Read more

Custom SQL Query: Get all posts with category id and a concated list of tags on each post

SELECT DISTINCT p.ID AS id, p.post_title AS title, ( SELECT group_concat(p2.guid SEPARATOR ‘, ‘) FROM wp_postmeta pm LEFT JOIN wp_posts p2 ON pm.meta_value = p2.ID WHERE pm.post_id = p.ID AND pm.meta_key = ‘_thumbnail_id’ AND p2.post_type=”attachment” ) AS image, ( SELECT group_concat(pm.meta_value SEPARATOR ‘, ‘) FROM wp_postmeta pm WHERE pm.post_id = p.ID AND pm.meta_key = ‘views’ … Read more

Get posts from specific taxonomy term

this code will display the post from all taxonomy in wordpress: $args = array( ‘type’ => ‘post’, ‘child_of’ => 0, ‘parent’ => ”, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘hide_empty’ => 1, ‘hierarchical’ => 1, ‘exclude’ => ”, ‘include’ => ”, ‘number’ => ”, ‘taxonomy’ => ‘season’, ‘pad_counts’ => false ); $taxonomy = get_categories( $args … Read more

How can I improve this taxonomy treating approach?

This is what functions.php is for. Add the function to functions.php, with just a slight modification that will allow you to pass in which category you want to get the children of: function the_categories_navigations_trees( $parent ) { $cat_data = get_categories( array( ‘parent’ => $parent, ‘hide_empty’ => 0 ) ); if ( $cat_data ) { $cat_links=””; … Read more

REST API: Display Category names in JSON?

For my needs, I customized the wp rest posts callback: function get_all_posts( $data, $post, $context ) { return [ ‘id’ => $data->data[‘id’], ‘date’ => $data->data[‘date’], ‘date_gmt’ => $data->data[‘date_gmt’], ‘modified’ => $data->data[‘modified’], ‘title’ => $data->data[‘title’][‘rendered’], ‘content’ => $data->data[‘content’][‘rendered’], ‘excerpt’ => $data->data[‘excerpt’][‘rendered’], ‘category’ => get_the_category_by_ID( $data->data[‘categories’][0] ), ‘link’ => $data->data[‘link’], ]; } add_filter( ‘rest_prepare_post’, ‘get_all_posts’, 10, 3 … Read more