WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
[resolved] using the jQuery load() method (5 posts)

  1. carlodurso
    Member
    Posted 1 year ago #

    Hi Hector,
    I'm actually using the jQuery load method to open posts on the main page.

    With this scenario looks like that the page views number doesn't update unless I open the post in single.php, in other words after I open the post as normal the page view number gets updated using the load() method.

    Do you have any suggestions?

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

  2. Héctor Cabrera
    Member
    Plugin Author

    Posted 1 year ago #

    Hi carlodurso,

    I've been thinking of a possible solution for this. See, when the page loads, my plugin uses ajax too to send the update to the database. In your case, you could try adding something like this to your script:

    <?php
    $nonce = wp_create_nonce('wpp-token');
    $id = 'YOUR-POST-ID-HERE';
    ?>
    
    jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', {action: 'wpp_update', token: '<?php echo $nonce; ?>', id: <?php echo $id; ?>}, function(data){/*alert(data);*/});

    I haven't tested this code, so let me know what happens.

  3. carlodurso
    Member
    Posted 1 year ago #

    Hi Hector,

    It works great, as expected. Thanks a lot.

    The only issue I have found is that it doesn't work when I'm logged in either as admin or normal user. It's not an issue for me but I thought it could be valuable for you.

    Finally, does it matter if I generate the $nonce outside functions.php? Right now I'm generating a custom tag in the footer thus I can copy it via jQuery.

    Thanks again for your help.

  4. Héctor Cabrera
    Member
    Plugin Author

    Posted 1 year ago #

    Glad to know that, Carlo.

    As long as a valid nonce is generated it shouldn't matter.

    About WPP not counting visits when logged in:

    WordPress Popular Posts is not counting my own visits, why?
    WordPress Popular Posts won't count views generated by logged in users. If your blog requires readers to be logged in to access its contents, this tutorial is for you.

  5. carlodurso
    Member
    Posted 1 year ago #

    Thanks for the info.

    Keep up your good work.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic