In the function widget( $args, $instance ), which generates the widget output, add the following code before the echo $after_widget; line:
// The Query
$the_query = new WP_Query( array( 'post_type' => 'page', 'posts_per_page' => '3' ) );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
endwhile;
Additional information can be found on the WordPress Codex.
Related Posts:
- How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?
- Add inline HTML to posts published within last 24hrs
- meta_query not working properly
- Show one post per author and limit query to 8 posts
- Pass the same object to multiple widgets in a template with one query
- How can i make WP_Query return post image and categories?
- Order posts by meta value and Date
- Retrieving list of a custom post type in a widget without using WP_Query?
- How to detect if query is runned from widget?
- Most commented last 24h, week, month, year and all time – posts_where
- Show post number in widget loop
- WP_Query with offset and ‘orderby’ => ‘rand’, offset not working
- Reset WordPress Post Query to default
- Error with function in functions.php?
- 2 column recent post query not respecting float right [closed]
- How to create a widget like this?
- Display recent posts on another site
- All Posts Have The Same Comments
- Widget only in first post
- Widgets: Show Recent Posts Only if the Posts Have Both Categories X and Y
- How can I show only last year posts in wordpress archive?
- date_query problem
- wp_query in form method of widget breaks customizer
- Wp_query to get woocomerce product categorys [closed]
- How to store and receive variables in WP sessions?
- Nested meta_query with multiple relation keys
- WP_Query vs get_posts
- Query Multiple Post types each with own meta query
- Display only posts with thumbnail using WP_Query
- Why is my WP_Query not working when tax_query terms are an array?
- Make First post different from rest?
- WP_query and pagination?
- pagenavi with merged wp_query [duplicate]
- How can I display recent posts from a particular category in my header?
- Search Custom Post with meta_value NULL
- Ajax Infinite Scroll In Custom WP_Query Loop Not Working
- Query two post types and order by two different date fields
- WP Query – Get WooCommerce Products with variation that is in stock
- Multiple search queries on one page
- Custom Post order for homepage
- Arrange BBpress topics by created
- Warnings in nav-menu when visiting query pages [closed]
- Page navigation doesn’t show when query category
- Sorting posts DESC based on the number of comments using WP_Query
- Create unique page without header.php for json feed
- $wpdb select date range of posts
- get_posts() not working with multiple statuses
- Performance when getting post meta for post retrieved by meta value
- Exclude an array
- WP_Query: “post_parent” and “post_type” combination returning strange results
- How to use the query hook/filter?
- Cutom wp_query for geolocation search, pagination not working
- Tax query AND/OR meta query [duplicate]
- WP_query return more results than SQL query. post_count > found_posts
- WP_Query (list) posts according to author’s custom field
- How to alter local query, not main query [duplicate]
- WP CLI can’t delete plugin related table
- Inserting HTML to close and open divs in WP_Query loops
- Change query from cat id to slug or name?
- Query only the posts with a post format of “audio”
- Display Current Post’s Position in Custom Taxonomy
- Using Wp_Query without the loop?
- Custom WP_Query id
- Change The Woocommerce Product Categories Dropdown Widget Placeholder Text
- Parent and child categories
- Can’t Write Custom Widget Code In One ECHO
- Set post number to single posts
- Orderby custom meta returns random order
- get_post() is not returning correct value
- Intiger meta value with ‘>=’ returns posts with lower value
- Update query for wp_posts and wp_postmeta
- How to print term name inside wp post loop
- Grabbing taxonomy terms and inserting them into an array
- WP_Query with page_ids in arguments without a result
- Query not sorting DESC
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Filter products on category AND tag
- meta_query – check for multiple meta values in key which holds an array of values
- How do I stop the same post showing multiple times in a archive?
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- WP_Query on custom key and value
- Set “editor” role to existing user
- how to get wp_query posts only first letter of alphabet A?
- How to mix two orderby-parameters into one ordered result
- Custom Post Type WP_Query with filters and search
- Get posts by similar names and categories
- Query by meta value (add a dropdown of all values)
- WP Query issue for multiple values
- Calling a function with WP_Query only ever brings the first result
- How To Query All Attachment Images Found In Post Galleries
- WordPress meta_query not working
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Paginate recent posts widget
- $wp_query when new WP_Query
- Divide WP_Query posts by date & post type
- Unable to pass variable
- WP Query get posts by specific author IDs if one of several logged in authors
- Edit WordPress loop, taxonomies, & filter
- WordPress website links redirect to homepage
- How to display posts from a specific term first then another posts from another terms using tax_query