【问题标题】:Shortcode with form shows duplicate entry fields带有表单的简码显示重复的输入字段
【发布时间】:2018-06-03 11:22:00
【问题描述】:

我为我的自定义帖子类型创建了一个搜索表单,我希望能够将其放置在我网站上的任何位置,因此我创建了一个简码。 vanilla 表单工作正常,但在简码中,它显示重复的字段。谁能明白它为什么会这样做?前 3 个字段与下方表单中的字段重复。你可以在http://autismva.teebark.com/resource-finder-3看到结果。

您可以在http://autismva.teebark.com/resource-finder2查看原版表单

function resource_search_form( $form ) {
$form = '<form id="category-select" class="category-select"  method="post" action="' . esc_url(admin_url('admin-post.php')) . '" >' .
    wp_dropdown_categories( 'show_count=1&hierarchical=1&depth=2&show_option_none=Select by category&name=$cat_id&taxonomy=resource_cat' ) . '<br>' .
    wp_dropdown_categories( 'show_count=0&hierarchical=1&depth=1&show_option_none=Select by age&name=$age_id&taxonomy=resource_age' ) . '<br>' .
    wp_dropdown_categories( 'show_count=0&exclude=128&show_option_none=Select by region&name=$region_id&taxonomy=resource_region' ) . '<br>' .
    '<input type="text" name="s" placeholder="Search by keyword" /><br>
    <input type="text" name="tag_name" placeholder="Search by tag" />
    <input type="hidden" name="action" value="resource_search_cat2" />
    <button type="submit" > Search </button>
</form>';
return $form;
}

add_shortcode('resource_search', 'resource_search_form');

**The vanilla form:**
<form id="category-select" class="category-select"  method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" >
    <?php wp_dropdown_categories( 'show_count=1&hierarchical=1&depth=2&show_option_none=Select by category&name=$cat_id&taxonomy=resource_cat' ); ?><br>
    <?php wp_dropdown_categories( 'show_count=0&hierarchical=1&depth=1&show_option_none=Select by age&name=$age_id&taxonomy=resource_age' ); ?><br>
    <?php wp_dropdown_categories( 'show_count=0&exclude=128&show_option_none=Select by region&name=$region_id&taxonomy=resource_region' ); ?><br>
    <input type="text" name="s" placeholder="Search by keyword" /><br>
    <input type="text" name="tag_name" placeholder="Search by tag" />
    <input type="hidden" name="action" value="resource_search_cat2" />
    <button type="submit" > Search </button>
</form>

【问题讨论】:

  • afaik 当您在短代码中使用它时,您必须将 echo=false 传递给 wp_dropdown_categories。您希望函数返回输出,而不是显示它。
  • 完美——非常感谢。

标签: php html wordpress forms shortcode


【解决方案1】:

我希望这对你有用。 // 在你的“after_setup_theme”钩子中写这个动作

add_action( ' woocommerce_single_product_summary ' , ' your_function_name ' , 10 );

//define your function that contains the removal action hook.
function your_function_name()
{
   remove_action( ' woocommerce_single_product_summary ' , ' woocommerce_template_single_add_to_cart ' , 30 );
}

【讨论】:

    猜你喜欢
    • 2013-03-25
    • 2022-01-02
    • 2013-09-19
    • 2015-05-23
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    相关资源
    最近更新 更多