WordPress 主题选项页面 query_posts

发布于 2024-10-04 08:40:57 字数 574 浏览 0 评论 0原文

我正忙于为一位客户构建一个小型主题选项页面,并且需要一些帮助来解决问题。

目前,我可以选择手动放入 WordPress 页面的 IDS,

以根据主题选项使用 query_posts 提取数据,创建一个名为 $euro_box_1_vehicles; 的变量,

我的选项已填充输入中的 as 32,39,43,54 ,当我用 echo 打印此语句时,得到相同的结果。

当我用 array($euro_box_1_vehicles) 替换 array(32,39,43,45) 时,它只返回一个结果。

<?php
    $vehicle1 = array(
        'post__in' => array(32,39,43,45),
        'post_type' => 'page',
    );

    query_posts( $vehicle1 ); 
    while (have_posts()) : the_post(); 
?>

I am busy building a small theme options page for one of clients and need some help with an issue.

currently i have the option to manually put in IDS of wordpress pages to extract the data with query_posts

based on the theme options is creates a variable called $euro_box_1_vehicles;

my options are filled in as 32,39,43,54 in the input, and when I print this statement with echo, I get the same result.

When I just replace array(32,39,43,45) with array($euro_box_1_vehicles) it only returns one result.

<?php
    $vehicle1 = array(
        'post__in' => array(32,39,43,45),
        'post_type' => 'page',
    );

    query_posts( $vehicle1 ); 
    while (have_posts()) : the_post(); 
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与他有关 2024-10-11 08:40:57

当我 echo var_dump = string(11) "32,39,43,45"

在这种情况下,您需要 爆炸 $vehicle1,因为 post__in 需要一个数组;

query_posts(array(
    'post_type' => 'page',
    'post__in' => @explode(',', $vehicle1)
));

When I echo var_dump = string(11) "32,39,43,45"

In which case, you need to explode $vehicle1, since post__in expects an array;

query_posts(array(
    'post_type' => 'page',
    'post__in' => @explode(',', $vehicle1)
));
那些过往 2024-10-11 08:40:57

更新

当我用 array($euro_box_1_vehicles) 替换 array(32,39,43,45) 时,它只返回一个结果。

难道您不应该将 array(32,39,43,45) 替换为 $euro_box_1_vehicles array($euro_box_1_vehicles >)?后者似乎会创建一个带有一个参数的嵌套数组,即 array(array(32,39,43,45))。这不是你想要的。


老答案...

如果我没看错的话,那么 query_posts() 需要一个 ID 列表? (32,39,43,45)

但是当你传递 $vehicle1 时,你并没有给它一个 ID 列表,而是一个二维数组。

<?php
    $vehicle1 = array(
        'post__in' => array(32,39,43,45),
        'post_type' => 'page',
    );

    query_posts( $vehicle1['post_in'] ); //use sub-array that contains list
    while (have_posts()) : the_post(); 
?>

Update

When I just replace array(32,39,43,45) with array($euro_box_1_vehicles) it only returns one result.

Shouldn't you replace array(32,39,43,45) with $euro_box_1_vehicles not array($euro_box_1_vehicles)? The latter seems it would make a nested array with one argument, i.e. array(array(32,39,43,45)). Which is not what you want.


Old Answer....

If I read you right then query_posts() expects a list of IDs? (32,39,43,45)

But when you pass it $vehicle1 you are not giving it a list of IDs, but a 2-dimensional array.

<?php
    $vehicle1 = array(
        'post__in' => array(32,39,43,45),
        'post_type' => 'page',
    );

    query_posts( $vehicle1['post_in'] ); //use sub-array that contains list
    while (have_posts()) : the_post(); 
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文