Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

Use existing tags on Wordpress front-end form

i have a frontend Form to allow users to create their own recipes. Currently I'm using this to allow entering new tags:

function display( $submit_type, $post_id ){

    $post_tags        = get_the_terms( $post_id, 'recipe_tags' );
    $post_tags        = ( is_array($post_tags) ) ? $post_tags : array();
    if( !empty($post_tags) ){
        $names = array();
        foreach ($post_tags as $term) {
            $names[] = $term->name;
        }
        $post_tags = $names;
    }
    $post_tags = ( ! empty($post_tags) && is_array($post_tags) ) ? join(', ', $post_tags) : '';

    $field = new Smk_Input( $this->id, $post_tags, array(
        'title' => __('Tags', 'smk_theme'),
        'description' => __('Enter a maximum of 15 tags separated by comma.', 'smk_theme'),
        'class' => 'fullwidth',
        'row_style' => 'inline',
    ) );

    echo $field->render();
}

So, I need that "$field" make them existing tags suggestions, just like Wordpress does on the post editing backend.

Can someone help me?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...