好的,假设您希望始终按相同的类别进行筛选(假设term\\u ID=28),那么您的代码应该如下所示:
function wpb_recentposts_dropdown() {
$string .= \'<select id="rpdropdown">\' .
\'<option value="" selected>Select a Post<option>\';
$args = array(
\'numberposts\' => \'5\',
\'post_status\' => \'publish\',
\'cat\' => 28, // <- this filters by category
\'orderby\' => \'title\', // <- this orders by title
\'order\' => \'ASC\' // <- this changes order to ascending (DESC is default)
);
$recent_posts = wp_get_recent_posts($args);
... // <- rest of your code
如果您想将该类别ID作为shortcode的属性传递,那么类似的内容应该可以帮助您:
function wpb_recentposts_dropdown( $atts ) {
$a = shortcode_atts( array(
\'cat\' => false, // <- you can put default cat ID here
), $atts );
$string .= \'<select id="rpdropdown">\' .
\'<option value="" selected>Select a Post<option>\';
$args = array(
\'numberposts\' => \'5\',
\'post_status\' => \'publish\',
\'orderby\' => \'title\', // <- this orders by title
\'order\' => \'ASC\' // <- this changes order to ascending (DESC is default)
);
if ( is_numeric($a[\'cat\']) ) {
$args[\'cat\'] = $a[\'cat\'];
}
$recent_posts = wp_get_recent_posts($args);
... // <- rest of your code