Use wp_reset_postdata() function after while loop to reset custom wp_query as shown in following code so that it will not break other wordpress loop.
<?php // Create and run custom loop
$custom_posts = new WP_Query();
$custom_posts->query('post_type=jobs&posts_per_page=8');
while ($custom_posts->have_posts()) : $custom_posts->the_post();
?>
<li><a href="https://wordpress.stackexchange.com/questions/98851/<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
For more information visit this page.
Related Posts:
- How to target the default Recent Posts and Recent Comments widgets with pre_get_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?
- 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
- Error with function in functions.php?
- How to create a widget like this?
- All Posts Have The Same Comments
- Widget only in first post
- How to add a recent post function to a text widget I created for practice?
- 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?
- wp_query in form method of widget breaks customizer
- Wp_query to get woocomerce product categorys [closed]
- order by numeric value for meta value
- numberposts? showposts? posts_per_page?
- $GLOBALS[‘wp_the_query’] vs global $wp_query
- Some doubts about how the main query and the custom query works in this custom theme?
- How to query posts based on lat-lng coordinate as post meta?
- How to query only for products with status “in stock” in WooCommerce? [closed]
- WP_Query displaying ALL posts
- Does WordPress sanitize arguments to WP_Query?
- How to trigger 404 for custom query var?
- WP_query taxonomy + get all posts with two terms from same taxonomy
- How do I create my own nested meta_query using posts_where / posts_join?
- Best Practice For Querying Grandchildren?
- How to combine tax_query and date_query in WordPress
- How to get any tag ID
- wp_query display posts from same category of the post
- Targeting specific pages in the loop
- WordPress custom archive page
- How to prevent queried posts from being added to cache?
- Order posts by meta value and Date
- Include Sticky Posts in Page Post Count for custom query
- Query sticky posts with thumbnails
- Show all parents and children in custom post type in right order
- How to make orderby ‘meta_value_num’ OPTIONAL?
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Can you order posts from wp_query by two custom meta fields?
- Retreaving all images attached to current post
- Pagination working everywhere but the index page
- How to select posts from one category but exclude posts in another category?
- Sticky posts are not showing at the top of category posts
- WPDB query – decrypting DB data
- Storing query variable and then using wp_reset_query
- ACF Date Based wp_query
- exclude posts with a specific custom field and value
- Redirect page when URL parameter not set
- list pages using page.php and NOT page-{slug}.php
- Moving the array pointer inside a WP_Query while loop
- Help with WP_Query – Too many mySQL queries
- Group and list posts by custom taxonomy
- Show scheduled posts in main loop but not in WP_Query?
- WordPress Pagination changes my template
- wp_query ignoring custom post_status
- Query posts(CPT, pages , hierarchical) by Ancestor ID
- Input check to custom post type query
- Get a list of posts with associated meta_value
- WordPress pagination not working on template search.php
- Show all data in database table and make it into an interactive table
- How to filter a query by date in a shortcode?
- Search posts missing a particular custom field
- Query post with meta value in set of values
- get_template_part causes 500 error
- Sort by presence of thumbnail
- Get posts in taxonomy randomly
- Max Posts and Memory Limit
- WP_Query orderby
- Using Ajax and WP_Query to load more posts on category page fails
- I have problems with the search query using multiple post types
- How to check if logged in user have pending custom post?
- How can I re-query post_type and rewrite the url?
- Different query result on local and server
- WP_Query about meta_key and its array value
- Related Post by Tags Code
- I can’t get post based on its postmeta value and key
- Change database image location for transportability
- Combine Tax Archive and Meta_Query in WP_Query
- Get posts by birthday
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Display three sequential posts on each page load, without repeating previous
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- Optimising amount of calls to custom fields
- Issue in If else condition [closed]
- Pagination not working with WP_QUERY
- Get Current CPT taxonomy category in shortcode
- Custom Content Slider stop duplicate
- Extract video content from post to display on front page
- Sort Posts with custom meta key by default which is currently set as optional
- wp_query pagination links producing 404
- Pagination problem with multiple loops on the same page
- Related posts with WP_Query
- Carousel slider with WP_Query to show 3 posts on each slide
- how to use transient method?
- WP_Query – meta fields numeric
- How to query posts from single post format on Genesis framework
- How to replecate the _fields parameter in custom REST api endpoint
- Display post format post in the sidebar