Articles of wp query

Get post thumbnail in WP_Query

I wrote an Ajax suggest plugin and I want to get the post thumbnail, but don’t know how. This is my plugin code: $s = trim( stripslashes( $_GET[‘q’] ) ); $query_args = apply_filters( ‘wpss_search_query_args’, array( ‘s’ => $s, ‘post_status’ => ‘publish’, ), $s ); $query = new WP_Query( $query_args ); if ( $query->posts ) { […]

Meta query with compare by more than 2 fields

i have 5 sets of meta boxes in some custom postype. So.. i know how to compare two meta box values… Example: ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => THEME_PREF.’source_lang_1′, ‘value’ => $sourceLang, ‘compare’ => ‘=’ ), array( ‘key’ => THEME_PREF.’target_lang_1′, ‘value’ => $targetLang, ‘compare’ => ‘=’ ), ), But… what if i […]

Orderby two meta fields not working

Good day. I have the following code: $args = array( ‘post_type’ => ‘property’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘rc_repl_status’, ‘field’ => ‘slug’, ‘terms’ => ‘sold’ ) ), ‘posts_per_page’ => 100, ‘meta_key’ => ‘_rc_repl_property_year_sold’, ‘orderby’ => ‘meta_value _rc_repl_property_acres’, ‘order’ => ‘DESC’ ); $query = new WP_Query( $args ); First I am filtering my post type […]

Get category name from custom loop and echo it once

I have a magazine front page that updates with every issue, and the front page shows the current issue posts which are stickied. So for example, this month all the posts are in a category titlted ‘Issue 01’ and next month, I will create ‘issue 02’ which will replace the ‘issue 01’ sticky posts on […]

Multiple meta query from array

I need to do multiple meta query from my array. I have something like this: $search_term[] = array( ‘key’ => ‘_cmb_listing_status’, ‘value’ => ‘Active’, ‘compare’ => ‘=’ ); foreach ( $refine_property_type as $search_value ) { $search_term[] = array( ‘key’ => ‘_cmb_property_type’, ‘value’ => $search_value, ‘compare’ => ‘=’ ); } And that gives output like this: […]

2 queries with counters

I have 2 loops on a page both containing a counter to implement slightly different code every 6 posts. For some reason though the second loop is implementing the different code sometimes after 4 items instead of 6. Am I not resetting the loop correctly? <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> […]

Searching post types

Is it possible to take a user input from a search form, use that to search a custom post type via the WP_Query class and then redirect the user to a page template to display the results? For example, Assume you have a search input that takes city, state or zip You then enter in […]

Query Posts, order by meta value

I’ve read a lot, tried a lot more, but can’t get what I want: I have custom post types, which I want to order in DESC, orderby its meta value: The complete query with its arguments: wp_reset_query(); $args = array( ‘meta_key’ => ‘completeness’, ‘order_by’ => ‘meta_value_num’, ‘posts_per_page’ => -1, ‘order’ => ‘DESC’, ‘post_type’ => ‘datensatz’, […]

Show single posts date, in a page of posts

In a page of posts, how do I show their date, instead of the page date? I have no php knowledge. Let’s say I want to show the single posts date here, instead to the single posts title. <?php if($block === ‘title’): ?> <h2 class=”post-title”> <?php echo empty($link_setting) || $link_setting != ‘no_link’ ? $this->getLinked( $post, […]

What is the difference between these two custom queries?

Could you please explain what the difference is between the following two custom queries? $arguments = array ( ‘post_type’ => ‘post’, ‘meta_key’ => ‘_count-views_all’, ‘orderby’ => ‘meta_value’, ‘tax_query’ => array( array ( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘term’ => ‘student-success-stories’, ), ), ); and $arguments = array ( ‘post_type’ => ‘post’, ‘meta_key’ => ‘_count-views_all’, […]