情報を追記している場合はありますが、古い情報を訂正はしていませんので、公開年月日を参照してください。プラグイン・タグ、いずれもワードプレス・PHPのバージョン等によって動作しない場合もあります。
https://wordpress.org/plugins/last-viewed-posts/
今後このプラグインが更新されるかどうかは不明ですが、覚書として。
一覧で10件取得。投稿タイプを限定しているので、if (get_post_type($value) === ‘property’ && get_post_status($value) == ‘publish’) {
function list_zg_recently_viewed() {
if (isset($_COOKIE["WP-LastViewedPosts"])) {
$zg_post_IDs = unserialize(preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", stripslashes($_COOKIE["WP-LastViewedPosts"])));
$i=0; foreach ($zg_post_IDs as $value) {
global $wpdb;
$zg_get_title = $wpdb->get_results("SELECT post_title FROM $wpdb->posts WHERE ID = '$value+0' LIMIT 1");
foreach($zg_get_title as $zg_title_out) {
if (get_post_type($value) === 'property' && get_post_status($value) == 'publish') { ?>
<a href="<?php echo get_permalink($value); ?>"><?php echo get_the_title($value); ?></a>などの表示内容<?php }
}
$i++; if($i==10) break; }
} else {
結果がない場合の表示内容
}
}
acf はthe_field(‘xxxx’,$value); のように。
表示用テンプレート側は
<?php if (function_exists('list_zg_recently_viewed')) { if (isset($_COOKIE["WP-LastViewedPosts"])) { ?>
~
<?php list_zg_recently_viewed(); ?>
~
<?php } } ?>
追記:PHP7で警告が出ます。