开发者

Custom wp post functionality

I do NOT intend to implement all the wp_post features.

The thing am interested in (which has been giving me problems cos am not getting the relationship right) is the sql that inserts and updates the values into 1. posts table 2. terms table 3. term_taxonomy 4 term relationship

tables when a post is made.

$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));
                }

            }

        }

开发者_开发技巧I am not getting the relationship between the four tables right, please how can i fix this?

(pls i am not working in a wordpress environment, but utilising wordpress structure)


You've got:

in ('$newq')

Based on your code, you're probably ending up with the likes of:

in ('tag1,tag2,tag3')

Rather than the needed and expected:

in ('tag1','tag2','tag3')


I think this is where my problem is:

$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";

the right thing to do:

$sql="insert into wp_term_relationships (object_id, term_taxonomy_id) values ('my_post_id', 'the term taxonomy id')";

thanks all

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜