我不打算实现所有的wp_post功能。
我感兴趣的是sql,它将值插入并更新到1.员额表2.术语表3.术语轴切开术4项关系
当一个帖子被制作出来时。
$sql="update wp_posts set post_title='$name', post_name='$slug', post_content='$freeRTE_content', post_category='$category', post_status='$post_status', comment_status='$comment_status', mode_application='$howtoapply', website_address='$website', company_email='$email', application_deadline='$last_date', advert_date='$advert_date', post_date='$date', featured='$featured', course='$course', location='$location', grade='$grade' where id='$id'";
if(mysql_query($sql, $link))
{
$expq=explode(',' , $q);foreach($expq as $key=>$value){$expq[$key]=trim($value);}$newq=join(',',$expq);
$sql="insert into wp_term_relationships (term_taxonomy_id) select term_taxonomy_id from wp_term_taxonomy tt, wp_terms t where name in ('$newq') and taxonomy='post_tag' and t.term_id=tt.term_id";
if(mysql_query($sql, $link))
{
$sql="update wp_term_taxonomy tt, wp_terms t set count=count+1 where name in ('$newq') and taxonomy='post_tag' and t.term_id=tt.term_id";
$result=mysql_query($sql, $link) or die(mysql_error($link));
}
}
}
我搞不清楚四张桌子之间的关系,请问我该怎么解决?
(请注意,我不是在wordpress环境中工作,而是使用wordpress结构)
您有:
in ('$newq')
根据你的代码,你可能会得到这样的结果:
in ('tag1,tag2,tag3')
而不是所需和预期的:
in ('tag1','tag2','tag3')
我想这就是我的问题所在:
$sql="insert into wp_term_relationships (term_taxonomy_id) select term_taxonomy_id from wp_term_taxonomy tt, wp_terms t where name in ('$newq') and taxonomy='post_tag' and t.term_id=tt.term_id";
正确的做法:
$sql="insert into wp_term_relationships (object_id, term_taxonomy_id) values ('my_post_id', 'the term taxonomy id')";
感谢所有