我有不同用戶的帖子,我創建了一個名爲「offers」的custom_post_type。當用戶在wordpress登錄時只能看到他自己的帖子和優惠。關聯自定義帖子類型與帖子或用戶
是否有可能提議與用戶關聯後(用戶只能創建一個職位
的問題是:我可以顯示的index.php文件後和archive.php圖標時後的用戶有「優惠」
我有不同用戶的帖子,我創建了一個名爲「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