关联自定义帖子类型与帖子或用户
问题描述:
我有不同用户的帖子,我创建了一个名为“offers”的custom_post_type。当用户在wordpress登录时只能看到他自己的帖子和优惠。关联自定义帖子类型与帖子或用户
是否有可能提议与用户关联后(用户只能创建一个职位
的问题是:我可以显示的index.php文件后和archive.php图标时后的用户有“优惠”
答
你似乎想做一个循环,一个循环,我不知道这是否是最有效的方式做到这一点,但我想它会工作:??
<?php
// First loop
while (have_posts()): the_post();
$author_id = get_query_var('author');
$offers = array();
// Second Loop
$i = 0;
$args = array(
'author' => $author_id,
'post_type' => 'offers'
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) :
while ($the_query->have_posts()) : $the_query->the_post(); // check if it has offers, if it has, loop over the offers
$offers[$i]['title'] = get_the_title(); // or anything you need
$i++;
endwhile; // close the loop
else: // if it has no post
continue; // we don't display the post
endif;
wp_reset_postdata();
?>
<div class="post">
<?php
the_title(); // or anything you need
foreach ($offers as $offer):
echo $offer['title']; // we display the title of the offer
endforeach;
?>
</div>
<?php endwhile; ?>
其实,你试图达到的目标有点骇人听闻,但我认为你可以,如果你给予不同的使用能力rs和关联功能与能够查看菜单项并编辑这些项目,看看:http://codex.wordpress.org/Roles_and_Capabilities –
谢谢@LouisXIV我有这种能力。用户只能看到他自己的报价和条目。问题是,如果用户有优惠,我想在index.php(帖子)中显示优惠图标。一些想法? – vektor
@LouisXIV我改进了这个问题(我认为:)) – vektor