我希望我的理解都是正确的:
显示自定义post类型中的特定自定义字段,post分配给自定义分类法中的特定术语,用于今天和昨天的最新条目,我无法解决此任务,但您可以使用标准WordPress工具尝试以下功能:
function show_latest48h_post_cf_in_term( $cpt, $tax, $term_slug, $cf ) {
/* vars */
/******************************************************/
$output = \'\';
$today_latest = \'\';
$yesterday_latest = \'\';
$timestamp = current_time( \'timestamp\' );
$today = strftime(\'%Y-%m-%d\', $timestamp);
$yesterday = strftime(\'%Y-%m-%d\', strtotime(\'-1 day\', $timestamp));
$today_ar = date_parse($today);
$yesterday_ar = date_parse($yesterday);
/* today */
/******************************************************/
// args
$args_today = array(
\'post_type\' => $cpt,
\'tax_query\' => array(
array(
\'taxonomy\' => $tax,
\'field\' => \'slug\',
\'terms\' => $term_slug
)
),
\'year\' => $today_ar["year"],
\'monthnum\' => $today_ar["month"],
\'day\' => $today_ar["day"],
\'meta_key\' => $cf,
\'posts_per_page\' => 1
);
// get today post
$today_query = get_posts($args_today);
if ($today_query) {
$today_latest .= \'<p>\' . $today . \': \' . get_post_meta( $today_query[0]->ID, $cf, true) . \'</p>\';
}
/* yesterday */
/******************************************************/
// args
$args_yesterday = array(
\'post_type\' => $cpt,
\'tax_query\' => array(
array(
\'taxonomy\' => $tax,
\'field\' => \'slug\',
\'terms\' => $term_slug
)
),
\'year\' => $yesterday_ar["year"],
\'monthnum\' => $yesterday_ar["month"],
\'day\' => $yesterday_ar["day"],
\'meta_key\' => $cf,
\'posts_per_page\' => 1
);
// get yesterday post
$yesterday_query = get_posts($args_yesterday);
if ($yesterday_query) {
$yesterday_latest .= \'<p>\' . $yesterday . \': \' . get_post_meta( $yesterday_query[0]->ID, $cf, true) . \'</p>\';
}
/* output */
/******************************************************/
if ($today_query || $yesterday_query) {
$output = $today_latest . $yesterday_latest;
} else {
$output = \'Nothing found\';
}
echo $output;
}