Use query link this. You are checking posts in $the_query
. but you have used $query
.
<?php
$custom_query = new WP_Query( 'posts_per_page=4' );
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile;
else :
get_template_part( 'content', 'none' );
endif;
wp_reset_postdata();
?>
Related Posts:
- Resetting post data to previous loop in nested loops
- Pagination returns 404 after page 20
- Make loop display posts by alphabetical order
- get custom post type by tag
- Query Custom Meta Value with Increment
- Identify which loop you are hooking into; primary or secondary?
- Group posts by custom field
- Transient pagination not working properly
- get_posts() seemingly ignoring post_type
- Woocommerce custom loop to show all the products [closed]
- Exclude first 5 posts of specific categories in the main loop
- How to bring specific post to front of wordpress loop?
- How to show the posts of some category first, and then all other
- Pagination stops at page 6
- Paginated HTML Sitemap
- Posts loop with pagination on a single post page
- Why does the_content not work like others for a set post id?
- WP_Query Order by Specific Post ID First
- How to limit total number of posts in wp query loop?
- How to change posts order on Category and Tag archives?
- Using one WP_Query object within the loop of another WP_Query object
- Pagination is broken and I need help fixing it
- WP_Query on custom field and order results
- how to merge a WPQuery array with a PHP array and use the Loop to Output the result
- How to vary post loop results layout and resume?
- Get a post from other loop each n-posts in the main loop
- Loop returning only 1 result
- Where is the WP_Query instance instantiated (when working with themes)?
- WordPress Loop and $post
- posts_per_page not working for first page of pagination
- Loop Performance > JSON files vs. WP_Query vs. REST API
- Excluding pages in WP_query using ACF
- reset to main loop doesnt work
- Some doubts about how the main query and the custom query works in this custom theme?
- Post loop for all taxonomy terms
- WordPress ignoring LIMIT / posts_per_page despite being in wp_query
- Stuck in the query loop
- Conflict with get_posts and the_content
- Only display post if published in last 24 hours?
- How to remove the most recent post from $the_query
- WP_Query loop else statement not executing
- Include current post into loop
- How to display the featured image for each post?
- How to provide meta_key array to wp_query?
- Check for the main query from the template
- Trying to retrieve random post, getting a page
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- has_excerpt() not working inside wp_query
- Save (and exclude) posts from loop to use in another loop on page
- Get all posts with empty meta_value
- Loop 3 posts column wise and continue the loop into same columns
- PHP – Loop custom post type categories within jQuery Tabs
- Check if a post has term inside loop
- WP_Query with one category in args shows other categories
- How to Order By Two Custom Fields?
- Display specific page (that is child) content on parent page
- Query Taxonomy By Page Title
- How to change the default post type over the loop?
- Query Not working as expected
- Compare “Main” post ID to ID inside wp_query loop
- Paginate pages with dynamic query
- WP_Query loop doen’t work with my custom taxonomy
- Determine if ID is page or post and query the ID
- Custom template for password protected page
- problem with the loop
- How can I do a orderby by the number of items? So basically list by starting with the array with the largest number of post
- get_children() Archive Template
- Populate select list with meta values from all posts of a Custom Post Type
- Prevent Duplicate Post Counted by Query
- show most viewed post
- Bootstrap grid while loop
- Woocommerce featured products query no longer working
- How can I use WP_Query to sort ‘event’ custom post type by date?
- Display posts side by side with custom query
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- Some doubts about how the main query and the custom query works in this custom theme?
- Retrieving category pages from subcategory returns empty sets
- Pagination returns 404 after page 20
- Ordering Posts by parent category, name ascending
- WP_Query a custom field value bringing back 0 results
- Set Transient on CPT
- Load 3 posts in flexslider slide [closed]
- Loop through multiple custom fields with increasing number
- Different number of posts showing in development vs production server
- Issue with WP_Query (need a array of selected ID’s)
- An archive page without post format (just standard post)
- Multiple wp_query loops showing first 5 posts on all pages instead of older posts[Resolved]
- How to exclude posts ordered by comment_count from subsequent wordpress loops using WP_Query?
- meta_query dates from an array
- Creating array to compare custom field values
- $query conflicting with other queries in the same page
- Pagination in custom query not working [duplicate]
- WordPress Post Looping? [duplicate]
- Remove 5 latest posts from the loop
- Exclude post formats in custom loop
- Help with showing text when something is entered in my search bar
- How to write a query-function as a query-shortcode?
- Print post data inside loop using theme content template
- First post outside of loop, homepage only?
- Show number of posts AND number on current page (cannot make it work)