您需要对此进行自定义查询。基本上,只需从posts表中提取1个结果的查询,其中post类型是您的自定义post类型:
global $wpdb;
// the name you gave to your custom post type
$post_type = \'my_custom_post_type\';
// this is the query string that we\'ll use with the $wpdb class
// selecting from the posts table where the post_type is your custom post type
// ordered DESC and LIMITed to 1 to get on the most recent entry
$query_str = "SELECT * from " . $wpdb -> prefix . "posts WHERE post_type = %s ORDER BY post_date DESC LIMIT 1";
// it\'s good practice to $wpdb -> prepare queries to the database
$results = $wpdb -> get_results( $wpdb -> prepare( $query_str, $post_type ) );
我用过
get_results
因此,您可以选择要使用的日期(创建日期或修改日期)