简体   繁体   English

用查询帖子联接表

[英]join table with query posts

I have a table: 我有一张桌子:

userbookmark
contants fields 
1-id
2- user_id
3- post_id 

I have a bookmark system, when a user presses 'Bookmark' it should insert this information: 我有一个书签系统,当用户按下“书签”时,它应该插入以下信息:

1-id  ( autoinc..)
2- user_id ( 1 for  example  )
3- post_id ( 1 for example )

What I want to do is to write a query to show bookmarked posts with table above. 我想要做的是编写一个查询以显示带有以上表格的加书签的帖子。 I want to write a JOIN but I don't know how to do it in Wordpress' syntax. 我想写一个JOIN,但是我不知道如何用Wordpress的语法来做。

Here's what I have tried: 这是我尝试过的:

<?php
     $args = array(
                   'cat' => '1',
                   'author' => '1',
                   'post_type' => 'post',
                   'posts_per_page' => 6,
                   'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
                   );

    query_posts($args);

while (have_posts()) : the_post();
 /* Do whatever you want to do for every page... */
?>
    <a href=""><?php the_title();?></a><br />


      <?php

endwhile;
?>

You have some options here 你这里有一些选择

http://codex.wordpress.org/Class_Reference/WP_Query http://codex.wordpress.org/Class_Reference/WP_Query

You can try filtering add_filter('posts_join', 'your_function'); 您可以尝试过滤add_filter('posts_join','your_function');

http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM