There is date_query
which can handle this and an SQL query is not a good practice when you can take advantage of WordPress Query API:
$pid = 1; // post ID here
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
'date_query' => array(
array(
'year' => get_the_date('Y', $pid),
'month' => get_the_date('m', $pid)
),
),
);
$posts = get_posts( $args );
print_r( $posts );
Hope that helps.
Related Posts:
- How to show related posts by category
- How to display posts by current user/author in a custom page template?
- How to get previous 10 days post from a specific date – WP Query
- Query only Posts from Both of Two Category?
- WordPress get posts by date without query_posts
- Can I set and show “important” post in my blog?
- Inserting custom data to the_post() during loop
- Why is querying posts messing up my pages?
- While loop articles – if statement order
- Display Posts with template on a Page
- Post Filtering by GET URL parameters
- How to give classname to post if post has no content?
- Get posts from current category?
- How to merge the content of posts that have the same title?
- get posts, run a custom query, and join the results
- WP_Query to get posts in a specific tag or has post_format
- How to get all post titles starting with numbers and symbols?
- Word count for all posts of all authors
- Keep featured content post in homepage with original order
- How to get post content by calling ajax?
- get all posts ID from a category
- Number of posts per page setting is not working?
- Show the title of the latest post by author
- Can’t show comments count per post outside loop
- is there a better way of combining this?
- Order post by year DESC and month ASC
- Featured Posts for Category Pages
- Quickest way to get last or oldest post date – WP Query
- Function to show random posts from a category
- Posts are not showing up on particular category
- get selected post using $_GET
- Encrypt / Decrypt Post Title and Details
- Improving WP_Query for performance when random posts are ordered
- Get posts by name and taxonomy term
- How To Get Posts With A Specific Word
- Limit popular posts by days
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Display all posts that were published before full post on single.php
- Two loops, one AJAX loop, exclude posts in first loop from second loop, loops are in different files
- Include sticky posts on the static page front page
- Get attachments for posts that belongs to a specific category
- Any way for get_next_post() to use the actual post order instead of publish order?
- Multi row post list
- posts_per_page option limits the number of Gallery items
- Nested WP_Query breaking loop
- WordPress query_posts by tag doesn’t work anymore(?)
- do more action after I publish a post
- Retrieve only posts from a specific user in wp-admin/edit.php
- WordPress website loads more posts than expected
- query post limits
- Query for first 3 posts to change the look and feel
- Why posts array is empty?
- How to create a “latest news” page showing a list of posts from blog category
- How to check in functions.php if there is data in a WP_Query?
- Shortcode with ‘year’ parameter
- On what hook can I get the queried object’s final state?
- Get the most recently modified post date of most recently modified post
- All categories displays the same posts
- Query function not executed between element [closed]
- WordPress query portfolio posts
- Display specific posts on home page
- How to get posts ordered by using their categories?
- WP_Query articles order by offset in collumns
- Display 3 posts with different HTML markup using a loop
- Getting posts from some categories plus some individual posts
- How to assign a post to a post parrent?
- get parent fields title, content excerpt etc
- AWS usage queries
- How to show multiple posts thumbnail, title and date in widget
- Move position in post list for a custom checkbox column
- I need to create “View Profile” and “Edit Profile” links by incorporating the Post Title/ID, but can’t seem to manage it
- Show only posts with titles/permalinks that do not contain certain words
- How to add first 3-4 post tags on WordPress Post Title
- How to fetch courses in all languages in WordPress?
- get_next_post() not working with future post status
- Extracting the permalink from a post instance
- How can I use query_posts to loop through posts and construct my own content?
- Assign a day of the week to post, e.g: Assign Monday to post and have it only appear when the day is Monday
- Posts page listing pages as well
- Show 5 posts and than 3 posts offset with pagination
- wp_query args with relation
- How to Get Position of a Post from a category and tag
- Querying posts from current category, using a variable as array argument
- Use special template for the first post in the loop
- Need help writing loop to display posts by categories in separate divs
- Modify WordPress loop after it has been run
- Query post category & remove any post id
- show latest authors blog post
- How to get only current images of a post
- Ordering posts alphabetically by meta keys and title
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- Remove duplicated posts in the loop if post has more than one category
- Retrieve latest post by multiple categories with ID
- How to limit the number of results for all query_posts on mysite
- External link not showing on post but showing on comment
- wp_query select if have comments
- How to limit post query to only return a total count of items with certain post statuses?
- Load posts from external source if not found in database
- Not displaying any articles on a custom made file
- Sort Posts Alphabetically Based on Specific Category (Divi)