【问题标题】:How to create a wordpress post using array values?如何使用数组值创建 wordpress 帖子?
【发布时间】:2016-12-17 15:58:00
【问题描述】:

我正在使用此代码在 DWQA 插件中创建帖子?但是,我的主题编辑器要死了。我面临什么问题? 函数 my_pre_save_post( $post_id ) {

// check if this is to be a new post
if( $post_id != 'new' )
{
    return $post_id;
}

// Create a new post
$post = array(

    'post_content'=> $post_content,
    'post_title'  => $post_title,
     'post_author' => $post_author,
    'post_category' => $post_category,
    'post_type'  => 'dwqa-question',
    'post_status'  => 'draft',
    'post_date'  => 'date_created',
    'show_in_menu' => 'post-new.php?post_type=dwqa-question',

);

// insert the post
$post_id = wp_insert_post( $post );

// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );

// return the new ID
return $post_id;

}

add_filter('acf/pre_save_post' , 'my_pre_save_post');

【问题讨论】:

    标签: php wordpress gravity gravity-forms-plugin


    【解决方案1】:

    我只是一个想法,但我没有尝试过。

    你需要/在wp-includes / query.php中添加函数

    这样的代码:

    function query_post($post_id) {
        $GLOBALS['wp_query'] = new WP_Query();
        return $GLOBALS['wp_query']->query($post_id);
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多