Maybe a bit less hacky:
$months = array();
while(....){
list($month, $year) = explode("https://wordpress.stackexchange.com/", get_the_date('n/y')); // eg. 7/11
if(in_array($month, $months)) continue; // skip
$months[] = $month;
echo '<li><a href="'.get_month_link($month, $year).'">'.get_the_date('F Y').'</a></li>';
}
If you’re only getting 6 posts and you don’t need pagination that I guess it’s OK to go this way.
Otherwise you need to build your own SQL query to pull out only one post for each month…
You could also try to make 6 queries for each month, like:
$january_posts = new WP_Query('monthnum=1&posts_per_page=1'));
Related Posts:
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Include a custom field in mysql query
- If Elseif Query
- Firing schema via code in functions.php doesn’t work
- WordPress default Search function inconsistent in WooCommerce Product Titles
- Adding number to date not working [closed]
- How can I add extra word in permalink when someone click download button?
- Saving and Restoring a Canvas on A Individual User Basis
- Increase offset while looping
- Seach custom post type posts only by meta fields?
- Long running queries
- wpdb php get_var query to get ID for URL image doesn’t work for ID over 999
- How to use thumbnail size of image if I’m only using src to get image
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- how to retrieve a value if a checkbox is checked
- How to pre populate a form field with a link of a current user’s author profile?
- Trouble checking if custom woocommerce checkout field is empty or not
- Trying to get a PHP variable defined in a custom post into a javascript file. Null value. Using wp_localize_script
- auto-populating custom nav with all items from custom post type
- Query if audio attachment AND/OR custom field
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- Add / Update Custom Fields After Select Pictures in Media Window
- conditional logic for front-end custom field edits
- Trying to retrieve post meta
- register_taxonomy() take much queries
- Automatic Shortcode Creation with Custom Fields [closed]
- Custom field values to taxonomy terms
- How would an if statement surrounding a custom field with two variables (holding values) look like?
- WordPress SQL injection
- Which is the correct way to conditionally enqueue a CSS file?
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- Custom Field IF/ELSE PHP
- Which PHP page is the Default Posts Page
- Odd / Even posts add class minus first post
- How to combine 2 php functions into one function with a custom field
- Remove the last X characters of a custom field value
- Advanced Custom Fields – display label and value only if value entered
- Is it possible to retrieve all posts with a certain value for metadata?
- Saving zero in meta box
- Non-Closing PHP Query in WordPress Loop
- unable to use ‘new WP_Query’ in AJAX call
- Find a way to retrive data updated through metabox plugin to web page
- Parse error: syntax error, unexpected ‘}’ on get_the_author_meta [closed]
- Why are the details of my todo not saving?
- How to check if a PHP string is different than meta field?
- Can’t save php string to a custom field
- Display custom field on 404 page outside loop
- Why does this update_post_meta function not delete the custom field itself?
- How to list commenters and days since last commented
- How to show/hide php table rows based on the content of custom fields
- Run str_replace on title and save the output to a custom field
- How to add div blocks after certain set of post
- How to overwrite orderby with add_query_var
- Can’t update multiple rows with $wpdb query
- Only show image from custom field when present
- working with term_relationships table
- how to get serialized post meta
- Hide Heading if ACF Field is empty
- Custom meta box values are not getting saved for my custom post type
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- WordPress query undefined offset in loop
- Can I make get_users() query global?
- WP_Query: getting posts where custom field exists
- How to show meta value code HTML after x paragraph
- Issue with custom loop in Archive page
- How to display SQL query that ran in WC_Order_Query?
- Creating an image from a custom field
- Custom Post type slider with thumbnail navigation
- User Meta Value not echoing despite Var_Dump Showing correct string
- WordPress loop by meta key that is an array? and how loop multiple arrays
- Parse error: syntax error, unexpected ‘}’ [closed]
- if custom field doesn’t exist, use post thumbnail instead, as image background
- Shortcode to pull posts
- WP All Import / Update stock quantity from multiple XML files
- How to store multiple custom meta box
- PHP -> SQL Query with Summing
- How to hide posts of a specific custom category in WordPress?
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Handling repeater data
- How to add data to a custom field at the wp_users table?
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- Concatenate Custom Field Value & HTML Value
- Output custom text field as unordered list
- Conditional featured image with youtube thumbnail
- WordPress PHP syntax doesn’t seem to be working correctly
- Querying for specific tags
- `update_post_meta` not working anymore
- Order a WP_Query by meta value where the value is an array
- How to get thumbnail with pure PHP in a WordPress database?
- Unable to render custom field after attempt to generate a list of recent post in page template
- Limit tags shown in post
- Add a custom class to the body tag using custom fields
- Why my query does not run with prepare
- Define category ID using get_post_meta
- Add a counter for mouseovers (custom field)
- Hide a div when a custom field is empty
- mySQL queries are executed twice on wordpress website
- List of Events with Multiple Dates: Only NEXT Date
- Echo array value
- Including Custom fields within the_content