シンプルなお気に入り一覧を表示したいテンプレートに以下の内容を入れることで表示されます。
$favorites = get_user_favorites();
if (isset($favorites) && !empty($favorites)) :
foreach ($favorites as $favorite) :
echo '<div>' . get_the_title($favorite) . get_favorites_button($favorite) . '</div>';
endforeach;
else :
// No Favorites
echo '<p class="text-center">お気に入りがありません。</p>';
endif;
表示するお気に入り一覧の内容から条件に合致しない投稿を外したりと、ループの内容をカスタマイズしたい場合は以下のように記述することで表示されます。
ex.カスタムフィールドでcontractsが’空’のもののみにする場合
$favorites = get_user_favorites();
if ($favorites) : // This is important: if an empty array is passed into the WP_Query parameters, all posts will be returned
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // If you want to include pagination
$favorites_query = new WP_Query(array(
'post_type' => 'post', // If you have multiple post types, pass an array
'posts_per_page' => -1,
'ignore_sticky_posts' => true,
'post__in' => $favorites,
'paged' => $paged, // If you want to include pagination, and have a specific posts_per_page set
'meta_query' => array(array(
'key' => 'contracts',
'value' => '空'
)
),
));
if ($favorites_query->have_posts()) : while ($favorites_query->have_posts()) : $favorites_query->the_post();
echo '<div>' . get_the_title(get_the_ID()) . get_favorites_button(get_the_ID()) . '</div>';
endwhile;
next_posts_link('Older Favorites', $favorites_query->max_num_pages);
previous_posts_link('Newer Favorites');
endif;
wp_reset_postdata();
else :
// No Favorites
echo '<p class="text-center">お気に入りがありません。</p>';
endif;
参考:https://gist.github.com/kylephillips/9fe12f195c671c989af3


