Try to replace
$id[$counter] = get_the_id();
with
array_push( $id, get_the_ID() );
to collect the post id’s into the $id
array.
Update:
If you also use $ids
instead of $id
:
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'desc');
$ids = array();
$products = new WP_Query( $args );
if ( $products->have_posts() ) :
while ( $products->have_posts() ) : $products->the_post();
array_push( $ids, get_the_ID() );
endwhile;
endif;
Related Posts:
- Getting only direct child pages in WordPress with get_pages
- Query multiple custom post types in single loop
- Inject post (from specific category) between posts in Loop
- Knowing the total number of posts before to get into the loop
- Build a content and excerpt grid loop with paging and options for # of posts
- How to loop over custom fields in a page template?
- Want to separate sections of posts. Can you restart loop?
- Alter secondary loop to exclude posts from current page category
- Two posts in same div – WP loop
- Easiest way to show total number of subpages
- Custom Loop through category menu to include sub categories
- Output 2 items within the Loop
- How to speed up a wordpress function with multiple loops?
- Custom excerpt function re-factoring
- How can I show the post thumbnail from the most recent of a certain post type, in widget?
- How can I add pagination and how can I change thumbnail size?
- $wpdb->flush(); breaks the loop
- Use object in template part
- Get first URL from post content
- Split loop into two columns, how to favor one side over the other
- Filter Select results based on selection
- Show css depending on activity type in BuddyPress activity-loop [closed]
- Iterate through posts based on array of categories
- Increase offset while looping
- How to add condition in wordpress loop? [closed]
- Alert Bar section within WP loop is displaying even though there are no posts
- remove post that has no content
- Checking array against author id in loop
- How do I Turn This Into An if statement?
- Load wordpress content in other domain
- Widgets in the loop if active
- Get post id within comments loop
- Syntax error when I try to insert my loop into an unordered list? [closed]
- How to get post ID in a Page?
- PHP Warning: strip_tags() expects parameter 1 to be string?
- Echo a shortcode div after every 3 posts
- How to avoid duplicates when creating recent network posts
- How to overwrite orderby with add_query_var
- variable value disappears in a second loop
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Why my loop isn’t working? [closed]
- Only show first image in foreach loop
- How to get current post category details inside “loop”?
- How to pass current loop data into nested loop
- Get all posts as an array ID => Name
- How to get post ID from button and pass title to Modal
- Wpdb get->results to out the the month from the db
- Display child page content of a specific parent on home page
- Do not duplicate posts with multiple categories in multiple loops
- Infinite Loop – WP_Query
- How to wrap every 3 posts in a div (and close the last div too) [closed]
- Dividing the loop to style post differently
- Limit tags shown in post
- Create Div Wrapper On 3rd Iteration Or When Query Loop Items Run Out
- WordPress loop is not working
- How to create Loop code for Menu using WordPress?
- Add class to every other posts using get_posts
- Problem in replacing the_content with the_excerpt()
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- Give ID to divs inside the loop
- Pagination contents not changing in Front page WordPress
- Display all categories including sub categories under a list ul
- Where does php code to load data go?
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Custom Loop.php having a loop inside a loop
- ACF – Get ID of relationship field in flexible content
- Latest posts feed with a specific post always first
- How to output values from a loop into a javascript array
- WordPress Ajax filter: Create two loops for different output styles?
- How to display sticky post always at the top (before regular post) in wordpress?
- Exclude category and post from loop in custom category.php
- How to sort (orderby) a query done by a template function before the ‘foreach’ loop?
- Making list of posts with chosen description
- How fix error in the WordPress loop?
- what’s the syntax for if the image exists get the image?
- how to remove replicating a tag inside loop?
- My query keeps looping infinitely ! how to stop it?
- Efficient way of querying for a “fallback” post?
- Loop 1 user randomly
- Create a hierarchical loop at predefined markup requirements
- enumerating custom taxonomies?
- Problems With Query and/or Template Part and/or PHP
- Two loops in one function
- How to display thumbnail if post is assigned one otherwise not
- Pagenav Not appearing on custom Template
- Error trying import one category on page
- Remove the_content From Loop
- Adding if statement to content for homepage
- Tables not showing divs and loop/php items
- WordPress post pagination on custom template not working
- Pagination in category.php not functioning
- For each loop will not append to the_content hook
- How to handle parent and child pages?
- Options.php loop won’t show!
- How do I remove blog entries from home page Twenty Eleven child theme?
- How to create a loop that will display one post and stop?
- Pagination not working properly
- I want to show image from custom field image on my custom page template
- Count the number of matching post names in foreach loop
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress