Articles of wp query

Display posts with date wordpress default

I’m trying to display last posts with WordPress date, not date from server. <?php $week = date( ‘W’ ); $year = date( ‘Y’ ); $query = new WP_Query( ‘year=’ . $year . ‘&w=’ . $week ); while ( $query->have_posts() ) { $query->the_post(); // Page title the_title(); } // end while // Restore original Post Data […]

WP_Query times out

I have a form with 20 inputs that runs WP_Query and recieves results via ajax. For some reason: query gets considerably slower when 5+ inputs are filled It takes like 10 – 15s with 7 input values 15 – 25s with 8 input values and it increases in big chuncks with every next input I’ve […]

WP_Query loop within WP_Query loop

I’m trying to use a custom WP_Query loop within another one to display data from the inner loop independently from the main loop. I found this solution but don’t really understand how to use it. Here is the code, it works but the main loop generate duplicate posts. <?php // define the main query $main_args […]

Paginated pages are showing correct content but pagination links are not

I am using a custom WP_Query to display posts on static front page. and generating numbered pagination links with paginate_links functions. This is the code I have… $latest_args = array( ‘post_type’ => ‘post’, ‘category__not_in’ => array( 3 ), ‘ignore_sticky_posts’ => 1, ‘paged’ => $paged, ); $latest_query = new WP_Query( $latest_args ); if ( $latest_query->have_posts() ) […]

order by multiple meta keys in pre_get_posts

I want multiple orderby meta_query eg: orderby(‘_property_price’ => ‘DESC’,’_property_featured’ => ‘DESC’) This is what I am doing $query->set(‘meta_key’,array(‘_property_price’,’_property_featured’)); $query->set(‘orderby’,array(‘meta_value’=>’DESC’)); In SQL, it should be like ORDER BY _property_price, _property_featured DESC Any Solution to this ?

posts_per_page not working

For whatever reason the posts_per_page parameter isn’t working. I already called it earlier in the template and I used wp_reset_query(), yet it’s not working with the second instance. Any idea why? <div class=”new_home_single”> <ul> <?php $the_query = new WP_Query( ‘posts_per_page=6’ ); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <div class=”posting_classs”> <a […]

WP Rest API v2 return posts with specific tag

I am trying to get posts from blog: http://christianconcepts.com/ which are tagged “appcontent”. I tried this querry: http://christianconcepts.com/wp-json/wp/v2/posts/?filter[tag]=appcontent but it I still get unfiltered results. For example, this post: http://christianconcepts.com/pdf-ebook-available/ doesn’t have “appcontent” tag but it is still returned. “REST API – Filter Fields” plugin is installed. Could someone help me?

Is it possible to create a shortcode that will query a post based on taxonomies?

I am working on a site that will be listing a few hundred products and we wanted to be able to quickly/easily show specific products on a page based on taxonomies. I have been doing some research and thought I was on the right track. First, I found this article on digwp.com which I thought […]

How to find if a post with custom_field == X exists?

I need to find if a post with a custom field X equal to Y exists in a wordpress installation. Should I do it with a simple sql query or is there something build in that can help me achieve it?

is_search was called incorrectly

I created a search form which searching by category filter and keyword input. The search form code is here- <form action=”<?php bloginfo(‘url’); ?>” method=”get” role=”search” class=”dropdown-form”> <div class=”input-group”> <span class=”input-group-addon”> <?php wp_dropdown_categories(array( ‘show_option_all’ => ‘all categories’, ‘class’ => ‘search_cats’ )); ?> </span> <input type=”search” class=”form-control” placeholder=”<?php esc_html_e(‘Search anything…’, ‘onepro’); ?>” name=”s”> <span class=”input-group-addon”> <button type=”submit”><i […]