每次我的一篇帖子被更新并且custom_field的值为'ja'时,我都试图创建一个新的帖子(类型事件)。 我不明白为什么要查询if($ customfield =='ja'){} 不起作用。
function create_event($post_id, $post, $post_before){
if (get_post_type($post) == 'product') {
$customfield=get_post_meta($post_id, 'custom_field');
if ($customfield == 'ja') { //this if query doesn't work
$author = $post->post_author;
$event = array(
'post_type' => 'tribe_events',
'post_title' => get_the_author_meta('firmenname', $author),
'meta_input' => array('post_id' => $post_id, '_EventStartDate' => '2019-06-04 00:00', '_EventEndDate' => '2019-06-04 23:59',
'test'=>$customfield)
);
wp_insert_post($event);
}
}
add action('post_updated', 'create_event', 10, 3);
答案 0 :(得分:0)
protected fun initRecyclerView(mAdapter: PagedListAdapter<out Any, out RecyclerView.ViewHolder>) {
if (mRecyclerView?.layoutManager == null)
mRecyclerView?.layoutManager = component.linearLayoutManager
if (mRecyclerView?.adapter == null)
mRecyclerView?.adapter = mAdapter
}
要获取变量值,您需要编写此代码
function create_event($post_id, $post, $post_before){
if (get_post_type($post) == 'product') {
$customfield=get_post_meta($post_id, 'custom_field', true);
if ($customfield == 'ja') { //this if query doesn't work
$author = $post->post_author;
$event = array(
'post_type' => 'tribe_events',
'post_title' => get_the_author_meta('firmenname', $author),
'meta_input' => array('post_id' => $post_id, '_EventStartDate' => '2019-06-04 00:00', '_EventEndDate' => '2019-06-04 23:59',
'test'=>$customfield)
);
wp_insert_post($event);
}
}
add action('post_updated', 'create_event', 10, 3);