arrays - 将多个 ACF 变量合并到一个数组中
问题描述
我正在使用 ACF 关系字段。我正在显示多个手动选择的帖子块。有一个最后一个帖子块,我想在其中排除所有之前手动选择的帖子。
如何制作所有 ACF 的数组以选择它们以将它们从循环中排除?
这是我到目前为止的代码(不工作,如果我只使用一个变量,它就可以工作)
<?php
$excluir = get_field('bloque_6_posts');
$excluir2 = get_field('bloque_2_posts');
$excluir3 = get_field('post_destacado');
$excluir4 = get_field('posts_destacados');
$excluir5 = get_field('bloque_4_posts');
$excluirtodo = array (
$excluir,
$excluir2,
$excluir3,
$excluir4,
$excluir5
);
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array(
'posts_per_page' => 9,
'paged' => $paged,
'post__not_in' => $excluirtodo
);
$the_query = new WP_Query( $args );
?>
编辑[已解决]:正如@disinfor 在评论中指出的那样,解决方案是 array_merge 而不是 array
解决方案
从评论中添加我的答案以帮助未来的访问者
您当前正在将数组数组传递给post__not_in
. 您需要使用array_merge
将数组组合成一个数组。
<?php
$excluir = get_field('bloque_6_posts');
$excluir2 = get_field('bloque_2_posts');
$excluir3 = get_field('post_destacado');
$excluir4 = get_field('posts_destacados');
$excluir5 = get_field('bloque_4_posts');
// NEW CODE HERE
$excluirtodo = array_merge(
$excluir,
$excluir2,
$excluir3,
$excluir4,
$excluir5
);
// END ARRAY_MERGE
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array(
'posts_per_page' => 9,
'paged' => $paged,
'post__not_in' => $excluirtodo
);
$the_query = new WP_Query( $args );
?>
推荐阅读
- flutter - 在 Flutter 中,定位的 Widget 如何在其父 Stack 区域之外感觉到轻敲?
- r - 美人鱼图换行
- javascript - JS 给对象赋值导致对象重复
- java - Junit测试用例初始化一个得到错误的类
- pl-i - 在哪里可以找到适用于 Windows 的 PL/I 编译器?
- r - 将新的观察结果添加到 R 中数据框中的列
- bash - bash - 字符串操作后修剪输入
- javascript - 使用带有页面导航的共享网络工作者上传文件
- talend - iSQLOutput - 仅更新选定的列
- laravel - Laravel 多对多多态关系:让每个记录具有更高优先级的孩子