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条)

报告相同问题?

悬赏问题

  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决