Is This Code Efficient – Or is there a better way?

I’d recommend caching – generating the HTML mark-up and storing that in a cache, and using that rather then generating the list on each page load. Of course, the cache would have to cleared if a recipe is ever added, removed or changes title. add_shortcode(‘recipe_list’, ‘recipe_query’); function recipe_query( $atts, $content ){ //Get mark-up from cache … Read more

Can’t get simple meta queries to work

It seems the ‘type’ => ‘string’ is not right From the codex type (string) – Custom field type. Possible values are ‘NUMERIC’, ‘BINARY’, ‘CHAR’, ‘DATE’, ‘DATETIME’, ‘DECIMAL’, ‘SIGNED’, ‘TIME’, ‘UNSIGNED’. Default value is ‘CHAR’. try and remove the above line from the code and check or try using the below instead. ‘type’ => ‘CHAR’

get_posts output always same post

This is because you are not passing the parameters in the correct way, taxonomy param needs to be passed under tax_query. Please replace the $args with the below:– $args = array( ‘posts_per_page’ => 4, ‘tax_query’ => array( array( ‘taxonomy’ => ‘tag’, ‘field’ => ‘slug’, ‘terms’ => ‘pp’ ) ) ); For more details check the … Read more

Get a list of posts by specific category

You can also use the following query for getting the results if you have author_id, post_status and cat_id with you. global $wpdb; $author_id = 1; $cat_id = 1; $post_status=”publish”; /* Post Titles */ $search_titles = $wpdb->get_col( “SELECT DISTINCT post_title FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) … Read more

Wp Query with multiple custom tag(taxonomy) by get the terms

Try this.. $terms = get_the_terms( $post->ID, ‘tag_blogcom’ ); foreach ($terms as $term) { $slugs[] = $term->slug; } $query = new WP_Query( array( ‘post_type’ => ‘blogcom’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘tag_blogcom’, ‘field’ => ‘slug’, ‘terms’ => $slugs, ), ), ‘posts_per_page’ => 10 ) ); Check the Taxonomy Parameters at WordPress Codex.

Does meta_value (array) work with ‘orderby’?

Researching more, I got it to work with the following code $post = array( ‘posts_per_page’ => 10, ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => ‘category-1’ ), ‘meta_query’ => array( array( ‘key’ => ‘custom-key’, ‘value’ => array(1,100), ‘compare’ => ‘BETWEEN’, ‘type’ => ‘NUMERIC’ ) ), ‘meta_key’ => ‘custom-key’, ‘orderby’ … Read more