trying to change from query_post to WP_Query

The problem here is caused by variable scope… Everything is fine, when you use global $wp_query, because it is a global variable and functions like have_posts and the_post are aware of that, so you can use them in template parts. On the other hand, you define your custom query. Then you get template part and … Read more

How to remove a post from results by ID after query?

Perhaps something like this would work? // Assuming $posts = new WP_Query( $args ); $post_to_remove = 123; // If using post objects foreach ( $posts->posts as $i => $post ) { if ( $post_to_remove == $post->ID ) { unset( $posts->posts[$i] ); break; // no need to continue the loop as the post has been found … Read more

Query post with content only

If I understand your question fully, I believe this is what you’re after. As far as I know… There is no WP_Query that you can use to accomplish this. However, you can use the $wpdb and make a custom query. global $wpdb; $q = ” SELECT * from {$wpdb->posts} p RIGHT JOIN {$wpdb->postmeta} pm ON … Read more

Query WP Posts, then list the taxonomies from those posts

Use WP_Query with date_query and within loop show only posts with ‘grantees’ taxonomy using is_object_in_term() $args = array( ‘date_query’ => array( array( ‘year’ => 2018, ), ), ); $the_query = new WP_Query( $args ); Then in loop // The Loop if ( $the_query->have_posts() ) { echo ‘<ul>’; while ( $the_query->have_posts() ) { $the_query->the_post(); if( is_object_in_term( … Read more

Query Posts | Combining multiple form inputs into query arguments to generate one filter result

I needed to make the array of categories separate to each other, as this is where the ‘AND’ is being applied: /* Filter Portfolio Post Results */ function portfoliofilter_filter_function(){ $args = array( ‘orderby’ => ‘publish_date’, // we will sort posts by date ‘order’ => ‘DESC’ // ASC or DESC ); // for taxonomies / categories … Read more

Show one post of each custom taxonomy

assuming all your constants are correct, it should just look like this $terms = get_terms(array(‘taxonomy’ => APP_TAX_STORE)); $tax = get_the_terms($id, ‘coupon_category’); foreach ($terms as $term) { $args = array( ‘post_type’ => APP_POST_TYPE, ‘posts_per_page’ => ‘1’, APP_TAX_TAG => ‘gutschein’, ‘orderby’ => array( ‘meta_value_num’ => ‘DESC’, ‘post_date’ => ‘DESC’, ), ‘tax_query’ => array( ‘relation’ => ‘AND’, array( … Read more

Get posts having meta value between two numbers

Your question isn’t clear, but I’m making the following assumptions: The user is submitting $_POST[‘search_option_money’]; You want to return all mycredit posts where $_POST[‘search_option_money’]; is between the offer_money_start and offer_money_end custom fields. The problem is that you’re misusing the key and value arguments of the meta query. The key is the name of the custom … Read more