The proper way to set up a secondary query, using your example code. Instead of this:
$posts = get_posts('numberposts=1&order=DESC&orderby=post_date&category='.get_cat_ID( 'سیاست' ));
Do this:
// Query args
$custom_cat_args = array(
'posts_per_page' => 1,
'order' => 'DESC',
'orderby' => 'post_date',
'cat' => get_cat_ID( 'سیاست' )
);
// Instantiate query
$custom_cat_query = new WP_Query( $custom_cat_args );
// Instantiate loop
if ( $custom_cat_query->have_posts() ) : while ( $custom_cat_query->have_posts() ) : $custom_cat_query->the_post();
// Normal loop markup here
// Close loop
endwhile; endif;
// Restore $post global
wp_reset_postdata();
Using this method, your custom query will play nicely with your main loop query, and any other secondary queries.
Related Posts:
- Display list of Sub-Categories and the posts they contain, within one main Category
- How would you create a “weekly” archive?
- Inside a loop, how to change CSS class based on category name?
- Category archive is displaying all posts rather than the specific category
- Do not show sub categories in the loop on archive-product.php
- Allow user to select categories that will display in post loop
- Insert HTML content in WP Query at specific point
- filter a loop base on specific category
- Show the number of the post
- How to get multiple loop in category.php, my scripts becomes madness
- 2 loops in archive.php (one for each category)
- Category Archives: Show posts categorized in parent category only
- Display posts on category archive organized into subcategories?
- Limit get_categories to show each category once
- Archieve.php not loading for custom post type
- Display single category name in woocommerce loop
- Question on using custom structures for categories
- Show Posts from Single Category Not Working
- Is there a reason I cannot get the current category in a loop?
- Pagination on category.php and tag.php not working
- new WP_Query all post in a category inside the loop
- Trying to get variables in hacked category dropdown
- How do I remove a category from a wordpress loop>
- Problem with different query loops (and “main loop”) on category template page!
- How to do paging in the loop?
- How to add orderby parameter for sorting on category.php
- How to Remove a Title from All Category and Tags Page?
- category__not_in and id values from variable
- Getting the category title / description returns first matching post?
- How to loop custom post_type from (a) specific category(ies)?
- How to display the parent category if only the child category has been chosen
- About title on a page
- Category tags with comma’s
- why get_the_post_thumbnail( the_ID()) echos extra post id
- Display posts of certain categories to specific user roles
- How do I retrieve the category ID (ugly permalinks) in my sub-navigation menu?
- Simple way to style posts of a single category differently in the loop and in single
- display category list year wise in wordpress
- Remove any product that is featured from regular display loop [WooCommerce]
- Two Sections on Woocommerce Catergory Page [closed]
- Category page returns 404 error
- Getting the Most Recent Posts from Multiple Categories
- Display subcategories in dropdown
- How to display post in custom file not in archive file?
- Display category title and three latest post inside the category
- More efficient way to list posts by category [duplicate]
- WordPress showing wrong category name
- Have posts that belong to multiple categories, exclude some categories from homepage
- Category nicename inside loop in wordpress
- Media (images, videos, etc.) not showing on Category page
- WordPress monthly archive category specific
- Show post categories
- Show multiple categories in query using redux framework variable
- Add description to categories menu in admin
- Get the ID of the current post’s child category
- Displaying year once in category.php [duplicate]
- what file I need to create to work date archive links?
- Archive filtering
- multiple values in an array for category__and does not work with WP_Query
- Show Secondary Sidebar on Category pages (archive)
- How to add icon over specific thumb
- Rebuilding a Site: How to Show Several Category Posts in Woo Framework Theme?
- Limit Loop to One Category
- Displaying a custom field in Category Archives
- Display post thumbnail for specific category outside the loop
- List post only under the category, exclude child category content
- Add multiple orderby with pre get posts
- How to differentiate the homepage structure from the category page structure in WordPress template?
- Filter Category Loop Dynamically
- Editing Loop So It Targets Specific Tags?
- the_category() doesn’t working in wp_query loop
- Conditional category query breaking?
- Problem: retrieving parent category’s first post
- How to detect /category and /tag base pages?
- How to get posts using category slug in ClassiPress?
- show only sub categories if available?
- Category sticky latest
- Posts made to category don’t show up (do show up on frontpage)
- List categories of a post hierarchically?
- Redirect Problems with Archive Page and GET variables
- Exclude parent categories from the_category() within the loop
- Exclude posts without category from loop
- Archives and Categories in Custom Menu
- WooCommerce shared categories
- Category name for all posts getting assigned to a single random post
- exclude certain categories form archive widget
- Category post count is not correct
- Display all categories but only if they have posts in them that have a specific tag assigned
- Include last post date in get_categories loop
- Different post slug based on archive
- List of post categories only associated to another custom taxonomy
- Products category search not working
- How can I order all subcategories alphabetical independent of the parent categories?
- How to get specific (grand parent) category of current post?
- How do I make an array to get the category name, dynamically, in an archive template?
- Custom Loop with certain number of one category
- how tho change number of posts in loop from specific categories
- How to prevent WordPress from redirecting single page to prefixed category archive with same name?
- Template category.php with page (no posts)
- In if…else condition, the else statement shows even if if statement is correct