Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP高级自定义字段_Php_Wordpress_Advanced Custom Fields - Fatal编程技术网

PHP高级自定义字段

PHP高级自定义字段,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,这可能是一个基本问题,但我似乎找不到正确的解决办法 在高级自定义字段中,我设置了一个字段组CD,在CD中有三个字段:标题、信息、作者,如果类别=CD,则该组显示 因此,当我用分类CD写一篇新文章时,我会填写这三个字段。CD类别中有10个职位 现在我遇到的问题是在一个页面上显示所有帖子 这是我试过的代码 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php query_p

这可能是一个基本问题,但我似乎找不到正确的解决办法

在高级自定义字段中,我设置了一个字段组CD,在CD中有三个字段:标题、信息、作者,如果类别=CD,则该组显示

因此,当我用分类CD写一篇新文章时,我会填写这三个字段。CD类别中有10个职位

现在我遇到的问题是在一个页面上显示所有帖子

这是我试过的代码

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

       <?php query_posts( array(      'posts_per_page' => -1,      'cat' => '6',     'CD' => ( get_query_var('CD') ? get_query_var('CD') : 1 ), ));

            if (have_posts()) {
               while (have_posts()) {
                  the_post();
            get_post_meta();
                } // end while
                } // end if
            ?>


            <?php endwhile; endif; ?>
我在这里更幸运,因为我正在打印一些信息,但是只有类别中的第一篇文章,它不断重复,我希望所有10篇文章都不要重复

我想我很快就会找到那些最后的指标了

谢谢

似乎
get\u post\u meta()
有变量,而您缺少变量


就像
get\u post\u meta($var)
预期的那样,但您只是在调用
get\u post\u meta()
。希望能有帮助。

我认为你的查询不正确

你需要抓住这个领域

get_field('YOUR FIELD NAME') );
然后循环并获取所需的子字段

the_sub_field('YOUR SUB FIELD');
范例

    <?php if(get_field('YOUR FIELD NAME')): while(has_sub_field('YOUR FIELD NAME')): ?>
        <img class="logo" src="<?php the_sub_field('logo'); ?>" />
        <h1><?php the_sub_field('title'); ?></h1> 
    <?php endwhile; endif; ?>

" />

举个例子。希望这有帮助…让我知道。

我无法让上面的解决方案发挥作用,谢谢大家的意见

到目前为止,这是我的解决方案

<h3><?php the_field('title', 475); ?></h3>
                    <?php the_field('info', 475); ?>
                    <?php the_field('author', 475); ?>
                        </div>
               <img src="<?php the_field('cd_image', 475); ?>" height="200" width="200" alt="" />

“height=“200”width=“200”alt=”“/>
然后我重复了一遍,把id从475改成了其他的,现在我把所有的帖子都放进去了,但是失败的是,我必须在这个代码中再添加新的帖子

我可以使用wp查询在变量中提取这4个字段,然后打印该变量,然后在类别中循环,直到所有帖子都打印出来吗?

我的解决方案(最后)希望这能帮助其他人

 <?php

           $args = array('cat' => 6);
           $category_posts = new WP_Query($args);

           if($category_posts->have_posts()) : 
              while($category_posts->have_posts()) : 
                 $category_posts->the_post();
        ?>
                <div class="article">
                <div class="articleinfo">
                <h3><?php the_field('title'); ?></h3>
                <?php the_field('author'); ?>
                <?php the_field('label'); ?>
                    </div>
           <img src="<?php the_field('cd_image'); ?>" height="200" width="200" alt="cd-image" />

            </div>

        <?php
              endwhile;
           else: 
        ?>

              Oops, there are no posts.

        <?php
           endif;
        ?>

“height=“200”width=“200”alt=“cd图像”/>
哎呀,没有帖子。
在所有柱子上循环,拉动我需要的ACF

 <?php

           $args = array('cat' => 6);
           $category_posts = new WP_Query($args);

           if($category_posts->have_posts()) : 
              while($category_posts->have_posts()) : 
                 $category_posts->the_post();
        ?>
                <div class="article">
                <div class="articleinfo">
                <h3><?php the_field('title'); ?></h3>
                <?php the_field('author'); ?>
                <?php the_field('label'); ?>
                    </div>
           <img src="<?php the_field('cd_image'); ?>" height="200" width="200" alt="cd-image" />

            </div>

        <?php
              endwhile;
           else: 
        ?>

              Oops, there are no posts.

        <?php
           endif;
        ?>