Well, try the below code-
$base_array = array(
'posts_per_page' => -1,
'fields' => 'ids',
'post_type' => 'cpt',
'post_status' => array('publish'),
'date_query' => array(
'after' => strtotime( 'previous week Monday' ),
'before' => strtotime( 'previous week Friday' )
)
);
$base = get_posts($base_array);
I’ve not tested it. But I tested that below code returns the perfect date-
date('Y-m-d',strtotime('previous week Monday'));
date('Y-m-d',strtotime('previous week Friday'));
It returns-
2016-10-24 and 2016-10-28
Related Posts:
- WP_Query vs get_posts
- get_template_part in for loop
- How-to exclude terms from the main query the most performant way?
- get_posts() seemingly ignoring post_type
- Conflict with get_posts and the_content
- Only display post if published in last 24 hours?
- Best choice for multiple loop in page?
- get_posts output always same post
- How to access $wp_query object from array of posts given by get_posts?
- Function using get_posts() with tax_query not working when called from functions.php
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- How to add date_query to meta_query array
- Populate select list with meta values from all posts of a Custom Post Type
- Related posts queries
- Ordering Posts by parent category, name ascending
- Both WP_Query and get_posts returning 1 post
- tax_query not working properly with get_posts
- When to use WP_query(), query_posts() and pre_get_posts
- Resetting post data to previous loop in nested loops
- Pagination returns 404 after page 20
- Make loop display posts by alphabetical order
- get custom post type by tag
- pre_get_posts with get_posts
- Query all posts where meta value is empty
- get_posts not finding argument: post_name
- A WP_Query that will look for posts after 2 weeks ago OR with a certain meta value
- Group posts by custom field
- Transient pagination not working properly
- Can not switch the queried post in pre_get_posts hook
- Woocommerce custom loop to show all the products [closed]
- Count posts returned by get_posts in external PHP script
- SELECT * FROM $wpdb->posts WHERE ID > 160
- How to show the posts of some category first, and then all other
- Pagination stops at page 6
- Paginated HTML Sitemap
- Adding multiple post queries with parent and children to page – Best Way
- Why does the_content not work like others for a set post id?
- How to limit total number of posts in wp query loop?
- Using one WP_Query object within the loop of another WP_Query object
- Create a sitemap without a plugin – get parent pages only?
- WP_Query on custom field and order results
- how to merge a WPQuery array with a PHP array and use the Loop to Output the result
- get_posts – find out if querystring was crap and fallback is used
- How to display 7 most recent days of posts?
- Creating query to show which editor (classic or block) was last used to edit a post/page
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- Where is the WP_Query instance instantiated (when working with themes)?
- Show post number in widget loop
- posts_per_page not working for first page of pagination
- 1/3 of posts different class
- Loop Performance > JSON files vs. WP_Query vs. REST API
- Search form not working with custom query?
- WordPress ignoring LIMIT / posts_per_page despite being in wp_query
- How to show more post at a given category?
- Get posts by list of post IDs ordered by those IDs?
- How do I rewrite this loop as a new WP_Query style-loop?
- How to provide meta_key array to wp_query?
- Trying to retrieve random post, getting a page
- Use WP_Query or query_posts() or get_posts() for optimizing a site?
- Specify strict ‘order by’ in WordPress query
- Create a page template for “top rated posts” but show full content and not just a list
- Meta query compare for ID’s greater than specific ID
- PHP – Loop custom post type categories within jQuery Tabs
- WP_Query with one category in args shows other categories
- Ordering posts by custom field and grouped by month
- relation OR instead of AND – Filtered term ID’s in loop
- Compare “Main” post ID to ID inside wp_query loop
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Why does apply_filters behave different inside and outside a loop?
- Custom template for password protected page
- problem with the loop
- How can I do a orderby by the number of items? So basically list by starting with the array with the largest number of post
- Why my query is not “Main_query”?
- Function the_posts_pagination() not compatible with WP_Query arguments
- Facing problem with tax_query results
- Prevent Duplicate Post Counted by Query
- How to show specify category template for both parent and child category
- Pagination inside the blog page not working
- Woocommerce featured products query no longer working
- Ajax buttons not working properly in WooCommerce when using wc_get_template_part
- Custom Query Pagination not working on static front page
- query all posts published by certain user id
- get_posts query caching?
- modifying the loop multiple times with arguments passed through ajax to wp_query
- WP_Query causing links to not work
- Retrieving category pages from subcategory returns empty sets
- Archive – Show Page Month Headers
- Iterate through ID’s in loop
- Loop through multiple custom fields with increasing number
- Different number of posts showing in development vs production server
- An archive page without post format (just standard post)
- Pull Instagram images into an existing loop?
- Multiple loop for “featured” items returns wrong posts
- Pagination in custom query not working [duplicate]
- How to write a query-function as a query-shortcode?
- Query custom post types by meta field in a term from custom taxonomy
- First post outside of loop, homepage only?
- How to retrieve _embed (etc) fields in get_posts custom query?
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise