【问题标题】:Custom wp post functionality自定义 wp 发布功能
【发布时间】:2011-05-27 00:30:23
【问题描述】:

我不打算实现所有 wp_post 功能。

我感兴趣的东西(这给我带来了问题,因为我没有得到正确的关系)是将值插入和更新到的 sql 1.职位表 2. 术语表 3. term_taxonomy 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 结构)

【问题讨论】:

  • “我不是在 wordpress 环境中工作,而是在使用 wordpress 结构” - 祝你好运! :-)

标签: php sql wordpress


【解决方案1】:

你有:

in ('$newq')

根据您的代码,您可能会得到以下结果:

in ('tag1,tag2,tag3')

而不是需要和预期的:

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

【讨论】:

    【解决方案2】:

    我认为这是我的问题所在:

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

    谢谢大家

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多