In your loop, you must refer to $wp_query
instance:
<?php
$args = array( 'post_type' => 'post', 'posts_per_page' => 3);
$wp_query = new WP_Query($args);
if ( $wp_query->have_posts() ) {
while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<h4><a href="https://wordpress.stackexchange.com/questions/266621/<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
<?php the_excerpt();
endwhile;
} else {
echo 'No posts';
}
wp_reset_postdata();
?>
Also, the_excerpt()
function takes one optional parameter, which is either Post ID
or $post
object. To control ‘more’ link, you use ‘excerpt_more’ filter.
Related Posts:
- WP Query Args – Title or Meta Value
- Whats the difference between post_limits and pre_get_posts?
- WP_Query by post ID doesn’t work if post is in custom post_status
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Tracing the life of a query
- Query all posts where meta value is empty
- WP_Query orderby taxonomy term value (numeric)
- How to get post meta value and post in one query?
- Revolution Slider Orderby Two Custom Fields
- wp query by search in titles only & put the posts in loop
- Get random terms
- Dynamically Override Fancy Title – Part II
- Woocommerce custom loop to show all the products [closed]
- Count posts returned by get_posts in external PHP script
- Pagination 404 errors for author posts query on author.php
- List the 5 most recent child pages
- Meta-value query
- WP_Query compare with dynamic values
- WP Rest API max limit include parameter?
- Adding multiple post queries with parent and children to page – Best Way
- Programmatically set ‘meta_query’ for filter
- WP Query Exclude and Start by Menu Order Offset
- WP_Query Excluding pages with Order is 0
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- Creating a custom search for a specific post type
- Show all post for a given category
- WP_Query create html structure
- How is WP_Query parsed to determine which template to request?
- new WP_Query(), have_posts() return false in user_register hook
- How to filter, restrict and return posts based on custom user meta information
- Masonry, WP_Query & paged – first page repeating, second page not loading
- Query posts intersecting tags and categories
- REST API: Limit Read Permissions for Default Endpoints
- Excluding pages in WP_query using ACF
- How to sort post by custom table value
- Pagination on static Posts page
- Custom WP query with polylang term
- Can I simplify in function column_default use of queries
- How to provide meta_key array to wp_query?
- wp query error while paging the posts
- Specify strict ‘order by’ in WordPress query
- get_the_terms – but only show 4 Posts
- Getting rid of unwanted nonSQL syntax characters when debugging a query
- array of meta values using WP_User_Query
- WP_Query object: what’s the difference between [query] and [query_vars]?
- Using post_where filter only on main query NOT sidebard new WP_Query
- How to avoid bypass of search bar rules?
- Hide products in uncategorized category from search results
- Is it possible to add relation between meta_query and tax_query?
- wordpress udpate query not equal to
- How to generate feed for custom template
- WP_Query with one category in args shows other categories
- WP Query – filtering terms with regex
- Custom navigation : show posts in sets of 4
- WordPress WP_Query compare not working?
- How to filter multiple queries with search?
- Excluded category from loop
- Add content depending on page loaded
- Custom template for password protected page
- WP_Query Class custom field parameters
- WP Query and multiple pages
- How to get all user posts from two post types in wp_query
- WP_Query for distinct meta values
- Group Product Types
- meta_query with meta values as serialize arrays
- pre_get_posts pagination not working
- Prevent Duplicate Post Counted by Query
- Save queried result into database
- Multiple WP_Query args combinations according to post type
- wp_set_object_terms() custom taxonomy not working correctly when using insert post
- WP Query by variable custom field
- WP_Query multiple value not working
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- Translating WP query into to SQL query
- Is my code correct?
- TAG Query showing only 1 result
- Tax_Query not working – connecting to second wordpress database
- How to search CPTs in draft using get_page_by_title()
- wp_query returns match with no criteria
- WP Query Meta Query
- pre_get_posts with WP_Query to prevent posts from specific tags
- How can I modify standard search query to include also ACF custom fields values?
- Empty ‘terms’ in ‘tax_query’ returns an empty array
- Archive – Show Page Month Headers
- Order WP_Query results in order other than ASC or DESC
- More efficient query to display posts in same sub-category?
- Return a single custom post from multiple meta queries
- Get post closest to today
- query post based on comparison
- Dynamically create array from page title
- Ordering Custom WP_Query loop by meta key value with pagination
- Pagination in custom query not working [duplicate]
- wp_pagenavi on WP_Query using customfields
- paginate_links() on page (shortcode output)
- $query_args for loop to only get posts from “current category”?
- How to write a query-function as a query-shortcode?
- Get posts using multiple values from ACF checkbox as meta query wordpress
- Why ignore_sticky_posts argument is in sticky post query?
- WP Query returning all posts when Meta_query is null