使用wordpress子页面填充选择框

时间:2018-03-08 14:00:27

标签: wordpress

我使用该函数来填充包含给定页面的子页面的选择框。

    function countries_select( $atts )
    {

        $args = array(
            'post_type'      => 'page',
            'posts_per_page' => -1,
            'post_parent'    => 10490,
            'order'          => 'ASC',
            'orderby'        => 'menu_order'
         );

        $parent = new WP_Query( $args );
        if ( $parent->have_posts() ) 
        {

            $option_return = '<select id="baw_jumpposts"><option selected="selected">Select</option>';

            while ( $parent->have_posts() ) : $parent->the_post();
                $option_return .= '<option value="'.the_ID().'">'.the_title().'</option>';
            endwhile;
        }
        $option_return .= '</select>';

        return $option_return;
    }
    add_shortcode( 'select_1', 'countries_select' );

它正在生成带有空选项的选择框,并显示选择框外部页面的ID和TITLE 代码在functions.php文件中

1 个答案:

答案 0 :(得分:1)

函数the_ID()the_title()在调用时显示(回显)它们的值。

您需要使用函数get_the_ID()get_the_title()来代替这些返回值而不是显示它们,以便您可以在PHP代码中使用它们。

相关问题