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 delete widget in WordPress?
- Counting instances of words in the results of a post query
- Search filter between promo and exact price
- query hook parse_tax_query function takes no effect
- Order post by modified date
- meta_query with meta values as serialize arrays
- Query posts by post type, author and post meta
- Is it possible to give a classname to specific comments in the WordPress admin?
- Populate select list with meta values from all posts of a Custom Post Type
- pre_get_posts pagination not working
- Prevent Duplicate Post Counted by Query
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- tax_query not working on custom post type
- Filter for each loop when WP_Query has no posts to show
- Save queried result into database
- Show child by slug, while knowing parent ID
- sanitize_post() is not sanitizing Post Object
- Display Most Recent Post Widget Title On Page
- Form checkbox value going to dynamic URL
- get_post_format is not returning standard
- Duplice post with standard WP loop – fixed by using query_posts() instead
- How to use the Term Object from a custom select field in a query
- ElasticPress is (aparently) messing with my search filters
- Random users always showing same 8 users
- get_posts function not returning any results
- how to include orderby value that is empty?
- Why last row deleted when refresh page
- meta_query – check for multiple meta values in key which holds an array of values
- Custom Taxonomy – Modify Function to Get Child Category
- How to sort wordpress posts already selected by WP_QUERY
- WP Query – grouping posts by same meta key, adding together values from another key
- Pagination repeating posts on search results
- I have problems with the search query using multiple post types
- setting offset to category number in archive page
- Woocommerce Get Orders By Meta Value
- Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query
- Pagination not working on archive.php template?
- WordPress Sub Category Archive, Show Extra Empty Page Number in Pagination
- Save large WP_Query to transient === false
- WP_Query breaking the loop in a nested loop
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- 3 posts from each existing category on one page
- WordPress Query for CPT that only shows posts within radius of current user’s geolocation
- Sort by price wpdb
- SQL to join u3g_users & u3g_meta_value with repeating data
- WP_Query for a taxonomy value OR a custom post type meta field
- How to make WPQuery custom post type work in Twig / Timber
- Meta query ignores multiple values of the key
- Posts per Page not working
- meta_query is overriding default search
- WP_query pagination on frontpage
- Custom Woocommerce Product Query
- Any way to use FETCH_KEY_PAIR with $wpdb?
- WP Query by 4 different taxonomies
- WP_Query no result if keyword contains number
- WP_QUERY order posts by two combined meta_value dates
- Trouble with serialized metadata
- Query by meta key and order by another meta key value
- How to get individual values from custom widget?
- How to display the category dropdown auto search list when key press?
- Redirect logged in users from a custom post type archive page if they don’t have a specific role
- Multiple WP_Query args combinations according to post type
- wp_set_object_terms() custom taxonomy not working correctly when using insert post
- pre_user_query vs pre_get_posts
- Exclude post from wp_query based on custom field boolean
- Categories In English version showing not canonical URL, instead shows query search result
- Custom WP Query order function possible?
- Can I alter the main loop to ‘orderby’ a custom callback?
- WordPress Meta Query Null Values Order
- WooCommerce WP_Query using tax_query returns no results (0 = 1)
- WP Query by variable custom field
- How sort products by calculate value? ( custom post meta, price, option)
- wc_get_products() return empty object
- Multiple meta_query not returning rows
- How can I filter products by meta in Woocommerce REST API?
- WP_Query multiple value not working