add_action( 'init', 'new_session' );
function new_session() {
session_start();
$domen = 'https://домен.ру/';
$http_referer = $_SERVER['HTTP_REFERER'];
if (strpos($http_referer, $domen) !== false) {
} else {
$_SESSION['http_referer'] = $http_referer;
}
}
$id_posta = get_the_ID(); ?>
<h3 class="blogpost-title gallery-show" data-modalid="<?php echo $id_posta ?>">
<?php if ( $id_posta == 48777 ) {
Тут свой тайтл
} else {
the_title();
}
if ( get_post_meta($post->ID, 'numphoto', true) ) : ?>
<span>(<?php echo get_post_meta($post->ID, 'numphoto', true); ?> фото)</span>
<?php endif; ?>
</h3><?php
add_action( 'init', 'set_views_cook' );
function set_views_cook() {
$viewed = array_map( 'intval', explode( ',', $_COOKIE[ USER_COOKIE . '_views' ] ) );
$viewed[] = $object_id;
setcookie(
USER_COOKIE . '_views',
implode(',', $viewed),
time() + 31536000,
COOKIEPATH,
COOKIE_DOMAIN,
false,
true
);
/*var_dump($_COOKIE[ USER_COOKIE . '_views' ]);*/
}
function wpse_104324_prevent_multiple_views( $meta_id, $object_id, $meta_key, $meta_value ) {
if ( $meta_key === 'views' ) {
if ( ! empty( $_COOKIE[ USER_COOKIE . '_views' ] ) ) {
$viewed = array_map( 'intval', explode( ',', $_COOKIE[ USER_COOKIE . '_views' ] ) );
} else {
$viewed = array();
}
}
}
add_action( 'updated_post_meta', 'wpse_104324_prevent_multiple_views', 10, 4 );
add_action( 'added_post_meta', 'wpse_104324_prevent_multiple_views', 10, 4 );