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]
- Can I force WP_Query to return no results?
- Use the page slug in a WP_Query?
- Sorting: custom query with orderby meta_value_num THEN by title
- paginate_links() adds empty href to first page and previous link
- Using OR conditions in meta_query for query_posts argument
- Get posts by menu ID
- count posts from custom taxonomy terms by year
- How to grab metabox value in wp_query meta_query key
- Woocommerce query by price range and custom meta key
- Get posts with condition on comment meta value
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- Move posts to top of WP_Query if in certain Taxonomy?
- WP_query ‘orderby=none’ Problem
- How can I create a WP_Query that returns posts where one meta_value
- ‘paged’ in wp_query doesn’t work
- Sorting meta_value as integer doesn’t work
- Display different number of posts from one category on the different pages
- How to display child posts in the parent category
- Get posts from the Main site to sub site – WordPress MultiSites Network
- Custom Field Query – Meta Value is Array
- WP_Query for showing specific post by id
- Ordering by meta_value AND date NOT WORKING with wp_query
- Query by custom dates in UNIX Time
- Custom WP Query from meta_value stored as serialised array
- Get List of all the Authors
- How to check if a post “does not have term” in conditional statement?
- WP_Query returns more results than expected
- Make WP_Query more efficient?
- unable to retrive parent page information
- Which method is faster to get a single post?
- Site not getting correct featured image from my query
- Using WP_Query within an mu-plugin
- Use more than one query, but prevent duplicates – at scale!
- WP Query related posts by tags
- How to add posts, manually, to a wp_query?
- wp_reset_postdata() does not work as expected
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- WP_query with OR relation between args[‘s’] and arg[‘meta_query’]
- Stale $GLOBALS[‘post’] after custom WP_Query empty result set bothers my template, whose fault is this?
- How to count posts with specific arguments
- Why post__not_in is ignored?
- WP Query with multiple tags by get the tags
- Woocommerce pagination and result count after custom loop
- Include latest author posts with pagination in single template?
- How to querry for an item that saved in an array?
- Is it possible to add an argument to a custom function added to a filter hook?
- Order by meta_key doesn’t work
- WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have
- CPT category post/content is not showing on my page, Please review my coede
- how to get category`s slug in WP_Query loop?
- Category based on post id
- Advise on Templates for Custom Queries
- accessing wordpress serialized data outside wp
- Strange behaviour of hierarchical taxonomy archive
- Is it normal that get_post() gets run 300 times and the content of those posts aren’t visible?
- How to sort wordpress posts already selected by WP_QUERY
- WordPress Sub Category Archive, Show Extra Empty Page Number in Pagination
- Doing $wpdb->get_results returns NULL, doing the same query in my DB returns correct value
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- Get posts having meta value between two numbers
- Merge wp-query and get_users
- WP_Query how to add a thumbnail to the first post from the last 5 posts?
- How order by works?
- taxquery taxonomy get terms
- Using modified ‘meta_key’ to set ‘orderby’ in WP_Query?
- WP_Query don’t working with fixed post_id and term_taxonomy
- Query posts in current category but not attachment format
- Using orderby with 2 meta keys
- wp_query – Modify $query to include duplicate content
- Query to get all the posts of more than 2 meta_value having same meta_key?
- Query specific number of posts for each post type in specific order
- Avoiding page loop
- Query Users by post count, last 30 days and display each users post count according to post type
- how do I exclude child categories from a wp_query?
- how to show only catergory titles on a page in wordpress
- Display post format post in the sidebar