我的问题是:我试图通过ajax显示一个附在帖子上的图片库。还可以通过ajax从主页动态加载帖子。然而,检索图像的查询返回一个空数组。奇怪的是same query 如果库是通过ajax加载的,而帖子是“传统”加载的,那么实际上是可行的。更清楚地说:
第一种情况:
我在索引中。php我通过索引中的ajax动态加载帖子。php
- 第二种情况:
- 我通过ajax动态启动图库,图库工作正常,下面是我用来检索附加图像的查询:
当然,不幸的是,我在第一种情况下“没有帖子”,而在第二种情况下一切都很好。。。有什么区别?// The post id I\'m fetching from the AJAX call that loads the gallery $post_id = intval( $_POST[\'post_id\'] ); $args = array( \'posts_per_page\' => -1, \'orderby\' => \'menu_order\', \'order\'=> \'ASC\', \'post_mime_type\' => \'image\', \'post_parent\' => $post_id, \'post_status\' => \'inherit\', \'post_type\' => \'attachment\' ); $images = get_posts( $args ); if ( $images ) : // Loop else : // No posts endif;
非常感谢您的帮助!
我单身。php(意味着帖子是传统加载的,而不是通过ajax加载的)