dongwenhui8900 2013-07-16 16:50 采纳率: 0%
浏览 64
已采纳

PHP高级自定义字段

This may be a basic question but i cant seem to find a correct solution.

In advanced custom fields I have set up a Field Group CD, in CD there are three fields, title, info, author and the group shows if the category = CD

Therefore when i make a new post with category CD I fill these three fields. There are 10 Posts in the CD categories.

Now the issue I am having is displaying all the posts on a page.

Here is the code I tried

<?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; ?>

This returned an error Warning: Missing argument 1 for get_post_meta(), called in /Volumes/shared/Digital/_Websites/londonconchord/wp-content/themes/conchord/t-disc.php on line 25 and defined in /Volumes/shared/Digital/_Websites/londonconchord/wp-includes/post.php on line 1792

I tried a different attempt

<p><?php query_posts( 'cat=6' ); 
      the_field('title');
      the_field('info');
      the_field('author'); ?></p>

I had more luck here as I was printing some information, however only the 1st post in the category and it kept repeating, i wanted all 10 posts and no repeat.

I think im close just looking for those final pointers

Thanks

  • 写回答

4条回答 默认 最新

  • dongya5893 2013-07-19 12:00
    关注

    My solution (Finally,) Hope this can help others

     <?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;
            ?>
    

    Loops through all posts and pulls the ACF i needed

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码