您可以用几种不同的方法来实现这一点。需要知道如何在当前快捷码中传递1自定义字段。
看起来你可能是这样做的:
[your_short_code price="how_are_you_setting_this"]
如果是这种情况,则可以添加更多属性,如下所示:
[your_short_code price="how_are_you_setting_this" next_field="set_this_field"]
// From your code above with adjustments.
public function listings( $atts ) {
global $post;
// You can add on to the default atts.
$atts = shortcode_atts(
[
\'orderby\' => \'date\',
\'order\' => \'asc\',
\'number\' => \'20\',
\'price\' => \'\',
\'next_field\' =>\'\',
],
$atts
);
// Not exactly sure what you are trying to do here.
$query_args = [
\'post_type\' => $post->post_type,
\'post_status\' => \'publish\',
\'meta_key\' => \'_al_listing_price\',
\'orderby\' => \'meta_value\',
\'meta_value\' => $atts[\'price\'],
\'order\' => $atts[\'order\'],
\'posts_per_page\' => $atts[\'number\'],
];
return $this->listing_loop( $query_args, $atts, \'listings\' );
}
另一种方法是:
// notice that the attribute fields has multiple fields separated by commas.
[your_short_code fields="how_are_you_setting_this,set_next_field,and_set_next"]
如果使用分隔的逗号,那么在php端的短代码中,需要执行以下操作:
// From your code above with adjustments.
public function listings( $atts ) {
global $post;
// You can add on to the default atts.
$atts = shortcode_atts(
[
\'orderby\' => \'date\',
\'order\' => \'asc\',
\'number\' => \'20\',
\'fields\' => \'\',
],
$atts
);
// This will make an array out of your comma separated fields.
$fields = explode( \',\', $atts[\'fields\'] );
// Not exactly sure what you are trying to do here.
$query_args = [
\'post_type\' => $post->post_type,
\'post_status\' => \'publish\',
\'meta_key\' => \'_al_listing_price\',
\'orderby\' => \'meta_value\',
\'meta_value\' => $atts[\'price\'],
\'order\' => $atts[\'order\'],
\'posts_per_page\' => $atts[\'number\'],
];
return $this->listing_loop( $query_args, $atts, \'listings\' );
}
希望这对你有帮助。