block_core_navigation_get_most_recently_published_navigation

函数
block_core_navigation_get_most_recently_published_navigation ( No parameters )

block_core_navigation_get_most_recently_published_navigation: 这个函数用来获取最近发布的导航块。它检索的是具有最新发布日期的导航块。

找到最近发表的`wp_navigation’文章。

function block_core_navigation_get_most_recently_published_navigation() {
	// We default to the most recently created menu.
	$parsed_args = array(
		'post_type'      => 'wp_navigation',
		'no_found_rows'  => true,
		'order'          => 'DESC',
		'orderby'        => 'date',
		'post_status'    => 'publish',
		'posts_per_page' => 1, // get only the most recent.
	);

	$navigation_post = new WP_Query( $parsed_args );
	if ( count( $navigation_post->posts ) > 0 ) {
		return $navigation_post->posts[0];
	}

	return null;
}

常见问题

FAQs
查看更多 >