3

私のウェブサイトには、Jetpack プラグインを使用して作成した小さなフォームがあります (コンタクト フォーム クリエーターが組み込まれています)。

artistcustom-post-type " " (投稿のタイトルを使用)から入力を選択するためのオプションを取得したい。それを行う方法はありますか?

[contact-field label='Artist' type='select' required='1' options='i want my titles go here separated by commas plus "other" option'/]

フィールドのコードは次のようになります。このページ テンプレートでいくつかの php+jquery を実行する必要があると思いますが、取得できないようです。

4

1 に答える 1

3

ある程度の創造性があれば、そうです、それは可能です:)

別のショートコードを作成して、「仮想」JetPackショートコードを作成します。

デフォルトのpostpost_typeを使用してこれをテストしました。

add_shortcode( 'my-jet-form', 'so_14003883_jet_form' );

function so_14003883_jet_form( $atts, $content ) 
{
    // Query our post type, change accordingly
    $posts = get_posts( array(
        'post_type'    => 'post',
        'numberposts'  => -1,
        'post_status'  => 'publish'
    ) );

    // Build an array of post titles
    $titles = array();
    foreach( $posts as $post )
    {
        $titles[] = $post->post_title;
    }

    // Convert array into comma sepparated string
    $posts_select = implode( ',', $titles );

    // Make JetPack shortcode
    $return = do_shortcode( '[contact-form][contact-field label="Name" type="name" required="1"/][contact-field label="Artist" type="select" options="' . $posts_select . '"/][/contact-form]' );
    return $return;
}

使用法

  • 希望の投稿タイプを調整します
  • do_shortcode元のショートコードに合うようにパーツを調整します
  • [my-jet-form]ショートコードを好きな場所に置いてください
  • voilà
于 2012-12-22T21:38:51.533 に答える