我使用的是高级自定义字段,我的问题是:我有几个露营者,可供不同数量的人使用。现在,我需要一个短代码来显示所有特定人数的所有露营者。短代码应该是这样的[shortcode_name, personens="x"]. 这个x 代表功能应过滤露营者的不同人数。
我的起始代码如下(显示6人的所有露营者):
function modell_nach_personenzahl_variabel() { 
    $args = array(
        \'post_type\'   => \'womos\',
        \'order\'       => \'ASC\',
        \'orderby\'     => \'personen\',
        \'field\'    => $atts[\'personen\'],
        \'numberposts\' => -1,
        \'meta_query\' => array (
            array (
                \'key\' => \'personen\',
                \'value\' => \'6\'
            )
        )
    );
 谢谢你的帮助。
 
                SO网友:user3135691
                这不是完整的工作代码,只是为了说明如何添加短代码和触发函数。
<?php
   // Check if ACF is available
   if(function_exists(\'get_field\')) {
       function modell_nach_personenzahl_variabel() {
           $args = array(
               \'post_type\'   => \'womos\',
               \'order\'       => \'ASC\',
               \'orderby\'     => \'personen\',
               \'field\'    => $atts[\'personen\'],
               \'numberposts\' => -1,
               \'meta_query\' => array (
                array (
                    \'key\' => \'personen\',
                    \'value\' => \'6\'
                )
            )
        );
        $query = new WP_Query($args);
        if($query->have_posts()):
            while($query->have_posts()):
             // for testing purposes
             echo "<pre>";
                print_r($query->the_post);
             echo "</pre>";
             ?>
                <h1><?php the_title(); ?></h1>
                <!-- get the rest of the fields -->
            <?php
            endwhile;
        endif;
       // Add the shortcode
       add_shortcode(\'filter-camper-nach-personen\', \'modell_nach_personenzahl_variabel\');
   }