Articles of wp query

Pagination for search results of custom post type

This question already has an answer here: How to fix pagination for custom loops? 4 answers

Remove post type filter added by the plugin in the final query

I am querying the post types based on the custom post type, but when printing the final query it also includes the post_type=’tribe_events’, which is due to plugin using for the events. But I have added the following parameters only in the query: $args = array( ‘post_type’ => ‘mycustomepost’, ‘posts_per_page’=>1 ); How to remove the […]

WP_Query Custom Post Type if Category ID Equals

I’ve setup a custom post type “slides” and I’ve created two categories for the slides custom post type: “slides-testimonial” (id = 7) and “slides-regular” (id=8). I would like to run a single loop, but use a conditional statement to compare the categories. The following code is not working with is_category. What am I doing wrong? […]

wp query error while paging the posts

i am new to wordpress and i am learning paging the posts but the code below isnt working and i cant find whats wrong. please help. the code: <?php $temp = $wp_query; $wp_query= null; $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1; $wp_query = new WP_Query( ‘posts_per_page=2&paged=’.$paged ); while ( […]

How to display the featured image for each post?

I have used the following code to display the featured image for each post, but nothing is showing: <div class=”thumbnail-img”> <?php $lastBlog = new WP_Query(‘type=post&posts_per_page=2&offset=1’); if ($lastBlog->has_post_thumbnail()) { while($lastBlog->has_post_thumbnail()) { $lastBlog->the_post_thumbnail(); } ?> <?php get_template_part(‘content-image’, get_the_post_thumbnail()); } ?> </div> <br> <?php if( $lastBlog->have_posts()): while($lastBlog->have_posts()): $lastBlog->the_post(); ?> <?php get_template_part(‘content-title’, get_post_format()); ?> <?php endwhile; endif; wp_reset_postdata(); ?> […]

Create a WP_Query where if the first value of the first row is equal to the second compare other value

I want to create a query of a custom post type where the order is by a custom field and I want if the custom fields are equal to compare a second custom field. $args = array ( ‘post_type’ => array( ‘sn_dr_ia’ ), ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘thePrice’, ); These are my arguments and […]

Update query for wp_posts and wp_postmeta

I had been assuming that ID in wp_posts is the primary key and that post_id in wp_postmeta is the foreign key but there is no relationship between them. How does these two tables relate each other? There is a meta_key and meta_value column where meta_key data are _sku, _price, and _stock. How can I use […]

Excluding posts with certain value of meta_key keeping posts without that meta_key

There are solutions for this problem, but what I could found, all of them are from long ago. So I am looking for a solution (if there is any) considering recent updates. I have a meta key wpse_city, which is a radio button with several values. Now I want to exclude posts with wpse_city = […]

Create an archive page for custom post type with custom taxonomy

I have a custom post type called ‘news’ with a custom taxonomy called ‘news category’. I’d like to create a wp query to return all ‘news’ posts of a certain ‘news category’ for example ‘press’. Is there a way to write this that is universal so I don’t need to make one for each ‘news […]

Pagination in html table is not working

I have a custom page template and I found a a PHP snippet that create a pagination in html table. But the code is not working properly. UPDATE: I change the code. But still the code is not working correctly, when I click on the 2nd page, the 2nd page displayed a blank page only. […]