【问题标题】:Wordpress: Submitting a post method form on single custom post type page returns 404Wordpress:在单个自定义帖子类型页面上提交帖子方法表单返回 404
【发布时间】:2016-05-08 03:38:16
【问题描述】:

我现在正在开发一个 Wordpress 主题。

我有一个名为 activity 的自定义帖子类型:

register_post_type($class::$post_type, array(
    'label' => $class::$post_type_name,
    'description' => $class::$post_type_description,
// ....

我正在编辑single-activity.php 模板,上面有一个表单:

<form id="form_main" method="post" action="">
    <?php wp_nonce_field(); ?>
    <!-- Other fields -->
</form>

当我打开网址http://localhost/activity/slug/时,页面运行良好。

但是当我提交表单时,即使用 post 方法请求 url,它会导致 404 响应,url 只是一样。

怎么回事?

【问题讨论】:

    标签: php wordpress wordpress-theming custom-post-type


    【解决方案1】:

    经过长时间调试,找到原因:$_POST字段影响查询。

    就我而言,我提交了一个包含键和值的字段:

    $_POST['title'] = 'new title';
    

    我打算用这个标题创建一个新帖子。

    但实际上,默认查询使用该字段作为where条件来过滤当前页面,最后没有结果。

    因此,在发布数据时,注意保留的字段名称:

    喜欢:

    • s
    • p
    • 标题
    • 页面

    有关更多信息,请查看文档。

    【讨论】:

      猜你喜欢
      • 2019-05-08
      • 2014-09-29
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-30
      • 1970-01-01
      • 2016-06-05
      相关资源
      最近更新 更多