Multiple meta query from array

$search_term is already an array of an array. When you eventually add that to your meta_query, you get an array of an array of an array, which will not work You are using AND as your relation operator which is the default for a multi-array meta_query. I would suggest that you drop that, and then … Read more

Get posts with no tags?

I’m not in the position to code right now, but here is an idea A thousand posts is quite a lot, but it is even more if you are retrieving all posts from the db in one go. What if you have ten thousand posts, of which only ten or twenty is not tagged after … Read more

Get post thumbnail in WP_Query

Do you mean the featured image? Use wp_get_attachment_image – Here is the code that I use in my plugin while ( $the_query->have_posts() ) :$the_query->the_post(); $image_id = get_post_thumbnail_id(); $imagesize=”thumbnail”; $image_url = wp_get_attachment_image_src($image_id, $imagesize, true); //do something endwhile; You can also use wp_get_attachment_url( $id );

Get posts by category name

list all the PAGES that are assigned to particular page(s). I’m assuming you mean “particular term(s).” which would be in your clinical-programs taxonomy. You’ll have to do a bit of coding – you need to start a new WP_Query and structure your query as such: $taxPages = new WP_Query( array( ‘post_type’ => ‘YOUR_POSTTYPE_HERE’, ‘clinical-programs’ => … Read more

How do I add an item to the WP admin menu?

You could do it with something like this in theme functions.php (at end) add_action(‘admin_menu’, ‘news_admin_test’); function news_admin_test() { add_menu_page( ‘News Page Title’, ‘News Option’, ‘manage_options’, ‘newspage’, ‘show_menu_news’, get_home_url() .’/wp-content/themes/my_theme/assets/img/logo.png’ ); } function show_menu_news () { echo ‘News content’; }

Get query results with a page title

There’s a problem with your get_page_by_title() usage, since you assume it returns the page ID, but it returns an object/array or null. You also have to tell it about your custom post type. I also assume your products are stored as custom post type cars. Please try the following with a given product title (untested): … Read more

How to set parameters for search loop?

You can modify search query and set your parameters with the help of pre_get_posts. Like this. function wpse_custom_get_posts( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_search() ) { $query->set( ‘post_status’, ‘publish’ ); } } add_action( ‘pre_get_posts’, ‘wpse_custom_get_posts’, 1 );

Use posts_where to exclude posts ids from wp_query

Instead of using posts_where it is a better idea to use pre_get_posts filter. Here is the code I end up implementing: add_filter( ‘pre_get_posts’, ‘hide_unwanted_posts_filter’ ); function hide_unwanted_posts_filter( $query ) { global $current_user; get_currentuserinfo(); $user_id = $current_user->ID; $key = ‘unwanted_posts’; $unwanted_posts = get_user_meta($user_id,$key,true); if(is_user_logged_in() && !empty($unwanted_posts) && !$query->is_admin) { $query->set(‘post__not_in’, $unwanted_posts ); // id of page … Read more

2 queries with counters

On the advise of Robert and Pieter I rewrote the loops using WP_Query instead of query_posts. It works now. Thanks guys. Here’s the code: <ul class=”tabs”> <li class=”tab-link current” data-tab=”tab-1″>Most Popular</li> <li class=”tab-link” data-tab=”tab-2″>Recent</li> </ul> <div id=”tab-1″ class=”tab-content current”> <div class=”slider”> <div class=”slide”> <?php $count = 0; $query = new WP_Query( array( ‘meta_key’ => ‘post_views_count’, … Read more