• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Jetpack a2z

Jetpack a2z

Jetpack a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Jetpack_Sitemap_Librarian::query_most_recent_posts() – Retrieve an array of published posts from the last 2 days.

You appear to be a bot. Output may be restricted

Description

Retrieve an array of published posts from the last 2 days.

Usage

$array = Jetpack_Sitemap_Librarian::query_most_recent_posts( $num_posts );

Parameters

$num_posts
( int ) required – Largest number of posts to retrieve.

Returns

array The posts.

Source

File name: jetpack/modules/sitemaps/sitemap-librarian.php
Lines:

1 to 39 of 39
  public function query_most_recent_posts( $num_posts ) {
    global $wpdb;

    $two_days_ago = date( 'Y-m-d', strtotime( '-2 days' ) );

    
/**
 * Filter post types to be included in news sitemap.
 *
 * @module sitemaps
 *
 * @since 3.9.0
 *
 * @param array $post_types Array with post types to include in news sitemap.
 */
    $post_types = apply_filters(
      'jetpack_sitemap_news_sitemap_post_types',
      array( 'page', 'post' )
    );

    foreach ( (array) $post_types as $i => $post_type ) {
      $post_types[ $i ] = $wpdb->prepare( '%s', $post_type );
    }

    $post_types_list = join( ',', $post_types );

    return $wpdb->get_results(
      $wpdb->prepare(
        "SELECT *
					FROM $wpdb->posts
					WHERE post_status='publish'
						AND post_date >= '%s'
						AND post_type IN ($post_types_list)
					ORDER BY post_date DESC
					LIMIT %d;",
        $two_days_ago,
        $num_posts
      )
    ); // WPCS: db call ok; no-cache ok.
  }
 

 View on GitHub View on Trac

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

Published: 27 November 2019 | Last updated: 27 November 2019

Primary Sidebar

Information

Function name: Jetpack_Sitemap_Librarian::query_most_recent_posts
Class ref: Jetpack_Sitemap_Librarian
Plugin ref: Jetpack
Version: 9.4
Sourcefile: modules/sitemaps/sitemap-librarian.php
File ref: modules/sitemaps/sitemap-librarian.php
Deprecated?: No
API Letters: J,L,M,Q,S

Footer

Jetpack a2z
Jetpack a2z
Jetpack a2z
WordPress 5.6.2
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  jetpack.wp-a2z.org
© Copyright Jetpack a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites