Php 使用自定义的“获取结果”查询显示WordPress上的帖子
我以前有这个代码来显示帖子Php 使用自定义的“获取结果”查询显示WordPress上的帖子,php,wordpress,Php,Wordpress,我以前有这个代码来显示帖子 $query_args = array( 'post_type' => 'post', 'posts_per_page' => 4, 'meta_key' => 'Views', 'orderby' => 'meta_value_num', 'order' => 'DESC',
$query_args = array(
'post_type' => 'post',
'posts_per_page' => 4,
'meta_key' => 'Views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'ignore_sticky_posts' => true
);
$the_query = new WP_Query( $query_args );
if( $the_query->have_posts() )
{
while( $the_query->have_posts() )
{
$the_query->the_post();
echo '<a class="popularPostLinks" href="' . get_the_permalink() . '" rel="external" target="_blank">' . get_the_post_thumbnail() . '
<br>
<div>
<p>' . get_the_title() . '</p>
</div>
</a>';
}
}
else
{
// No posts found.
}
// Restore original post data.
wp_reset_postdata();
我如何使用上面的数组结果来显示帖子,就像WP Query显示帖子一样?$getAllTimeRows包含最多4行以显示最多4篇文章。请参见下面的阵列
print_r ( $getAllTimeRows )
Array
(
[0] => stdClass Object
(
[post_id] => 213
[Views] => 16
)
[1] => stdClass Object
(
[post_id] => 215
[Views] => 11
)
[2] => stdClass Object
(
[post_id] => 217
[Views] => 9
)
[3] => stdClass Object
(
[post_id] => 227
[Views] => 7
)
)
您将修改SQL查询以加入wp_posts表并获取post_id上的id。谁为您创建了该SQL查询?我自己创建的。当用户看到一篇文章时,我将其id存储在我的自定义表中。但是我不知道如何显示这些文章id。从{$wpdb->prefix}PopularPosts作为P left join wp_posts作为W on P.post_id=W.id或其一些变体…jist告诉您需要join语句。
print_r ( $getAllTimeRows )
Array
(
[0] => stdClass Object
(
[post_id] => 213
[Views] => 16
)
[1] => stdClass Object
(
[post_id] => 215
[Views] => 11
)
[2] => stdClass Object
(
[post_id] => 217
[Views] => 9
)
[3] => stdClass Object
(
[post_id] => 227
[Views] => 7
)
)