Skip to content

Instantly share code, notes, and snippets.

@alanef
Created September 9, 2020 22:01
Show Gist options
  • Select an option

  • Save alanef/2ccee4251731ce5c79f9b2db5d979aeb to your computer and use it in GitHub Desktop.

Select an option

Save alanef/2ccee4251731ce5c79f9b2db5d979aeb to your computer and use it in GitHub Desktop.
global $wpdb;
$querystr = "
SELECT $wpdb->posts.ID
FROM $wpdb->posts
WHERE
$wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post
AND ABS(DATEDIFF(CONCAT('2000',SUBSTRING($wpdb->posts.post_date_gmt,5)), CONCAT('2000',SUBSTRING(NOW(),5))))< 16
";
$ids = $wpdb->get_results($querystr, ARRAY_N);
//To get a array of IDs
//then use them in a query
$the_query = new WP_Query( array (
'post__in' => $ids,
'post_type' => 'post',
'post_per_page' => -1,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment