PHP高级自定义字段
这可能是一个基本问题,但我似乎找不到一个正确的解决方案。PHP高级自定义字段
在我已经设置了场群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; ?>
这将返回一个错误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
我尝试了不同的尝试
<p><?php query_posts('cat=6');
the_field('title');
the_field('info');
the_field('author'); ?></p>
我在这里更多的运气,因为我是打印一些信息的代码,但只有第一个职位的类别,并不断重复,我想要所有10个职位,不重复。
我想我只是接近寻找那些最终指针
感谢
我的解决方案(最后)希望这可以帮助别人
<?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;
?>
遍历所有的帖子,并拉我需要
似乎get_post_meta()
有变量,你缺少它。
像get_post_meta($var)
预计,但你只是打电话get_post_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="" />
然后我重复这一点,并改变了编号从475到其他人,现在我牵扯到所有的帖子,但是失败的是,我不得不在这个代码中再次添加任何新帖子。
我可以使用wp查询将这4个字段放入一个变量中,然后打印该变量,然后遍历该类别,直到打印所有帖子为止?
'的ACF?> Havenard