wordpress查询随机从帖子类型中获取所有图像
我使用下面的查询从“myportfoliotype”post类型中获取所有图像,该类型工作正常 但是,我希望在加载/刷新页面时,所有拉入的图像都是随机的 我遵循了一些教程,并得出了以下代码:wordpress查询随机从帖子类型中获取所有图像,wordpress,Wordpress,我使用下面的查询从“myportfoliotype”post类型中获取所有图像,该类型工作正常 但是,我希望在加载/刷新页面时,所有拉入的图像都是随机的 我遵循了一些教程,并得出了以下代码: <?php $query = new WP_Query( array( 'post_type' => 'myportfoliotype', 'posts_per_page' => -1, 'orderby' => 'rand' ) ); if( $query->have_po
<?php
$query = new WP_Query( array( 'post_type' => 'myportfoliotype', 'posts_per_page' => -1, 'orderby' => 'rand' ) );
if( $query->have_posts() ){
while($query->have_posts()){
$query->the_post();
$do_not_duplicate = $post->ID;
$thumb_id = get_post_thumbnail_id( $post_id );
$image_query = new WP_Query( array('post__not_in' => array (MultiPostThumbnails::has_post_thumbnail('myportfoliotype', 'logo'), $thumb_id ), 'orderby' => 'rand' , 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'image', 'posts_per_page' => -1, 'post_parent' => get_the_ID() ) );
while( $image_query->have_posts() ) {
$image_query->the_post();
$do_not_duplicate = $post->ID;
//echo wp_get_attachment_image( get_the_ID() );
$image = wp_get_attachment_image_src(get_the_ID(), 'large');?>
<li> <a class="fancybox" rel="gallery1" href="<?php echo $image[0]; ?>"> <img src="<?php echo get_template_directory_uri(); ?>/js/timthumb.php?src=<?php echo $image[0]; ?>&w=137&h=137&f=2" alt="<?php the_title(); ?>" class="grey"/></a>
<img src="<?php echo get_template_directory_uri(); ?>/js/timthumb.php?src=<?php echo $image[0]; ?>&w=200&h=200" alt="<?php the_title(); ?>" class="color"/>
</li>
<?php
}
}
}
?>
/js/timtumb.php?src=&;w=200&;h=200“alt=”“class=“color”/
我不太确定这是不是正确的?正如前面提到的,它会拉入图像,但不是随机的
任何帮助或指导都将不胜感激
干杯,丹你可能有一个挂在过滤器上的插件
如果你不想禁用这个插件,你可以将
'suppress\u filters'=>true
添加到你的参数中。我已经解决了我的问题,尽管我会发布答案,以防其他人使用“post type order”插件遇到同样的问题
在“post type order”的设置页面中,有一个名为“自动排序”的选项,您需要取消选中该选项,并且在进行查询时,您应该添加以下内容:
$args = array(
'post_type' => 'post-type-here',
'orderby' => 'menu_order',
'order' => 'ASC'
);
就这么简单
感谢所有的帮助!你使用WP Engine吗?不,我没有我自己的专用服务器,我在网站的其他地方有随机功能。有点奇怪!请在第二次循环后添加
echo$image\u query->request;
并将结果添加到你的问题中。我得到以下信息:选择WP\u帖子。*从WP\u帖子E 1=1,wp_posts.ID不在(02349)中,wp_posts.post父项=1375和(post_mime_类型,如'image/%')和wp_posts.post_类型='attachment'和(wp_posts.post_状态='inherit')按wp_posts.menu_ORDER,wp_posts.post_date DESC IMG_3219-700×466 IMG_3219-700×466好吧,你的orderby参数被忽略了,请在你的第二个循环后添加echo$image\u query->query\u vars;
。你是否使用了任何可以钩住posts\u orderby
过滤器的插件?之前刚刚给出了这个,但它不起作用。我是否将它添加到po中st查询(第一次查询)或图像查询(第二次查询)?第二次查询,或仅禁用插件。