WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
possible fix for using WPP with other plugins (1 post)

  1. miscon2
    Member
    Posted 3 years ago #

    Pretty new to WPP, so apologies if this is known (either to be good or bad), but hoping it might help some folks.

    I'm using WPP on a site that includes BuddyPress. BuddyPress is a good example of a plugin that generated pages that don't have post ids associated with them, per se.

    I've found this to cause JS errors on such pages, as the basic wpp_update call is looking for an $id param, which equates to null. I altered wordpress-popular-posts.php to first check to see if it has an id before firing the wpp_update call:

    // if we're on a page or post, load the script
    			if ( (is_single() || is_page()) ) {
    				$id = $wp_query->post->ID;
    				if($id){
    			?>
    <!-- WordPress Popular Posts v<?php echo $this->version; ?> -->
    <script type="text/javascript" charset="utf-8">
        /* <![CDATA[ */
    	jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', {action: 'wpp_update', token: '<?php echo $nonce; ?>', id: <?php echo $id; ?>});
        /* ]]> */
    </script>
    <!-- End WordPress Popular Posts v<?php echo $this->version; ?> -->
                <?php
    				}
    			}

    (note the if($id) )
    ... and this seems to have resolved the issue.

    If there's a better way, or this is actually straight-up bad, please let me know!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic