• Hello,

    I am trying to create a function for count post views.For this i have added code and new table in my theme functions.php file. My insert and update queries work when i am logged in but when i am guest/ logged out user this code not work. Please help me.

    Here is code:

    global $wpdb;
    $sql = $wpdb->prepare("
    				INSERT INTO " . $wpdb->prefix . "postviews (id, type, period, count)
    				VALUES (%d, %d, %s, %d)
    				ON DUPLICATE KEY UPDATE count = count + %d",
    				$id,
    				$type,
    				$period,
    				$count,
    				$count
    			); 
    
    		$wpdb->query($sql);

    Please help , Its urgent

The topic ‘insert query not work in wordpress for non login user’ is closed to new replies.