Ready to get started?Download WordPress


Show More posts script not disabling other scripts (1 post)

  1. brockman.eric
    Posted 1 year ago #

    I have a website I'm working on here: http://taste.stage.fourseasons.com/ingredients/

    The problem is that with each post there's an option to vote on it, but when the user clicks view more posts, the voting script does not work.

    I believe this is because the the event handling script is invoked before the new elements are brought into the DOM, but I'm not sure how to fix it.

    The voting function looks like this

    add_action("wp_ajax_add_votes_options", "add_votes_options");
    add_action("wp_ajax_nopriv_add_votes_options", "add_votes_options");
    function add_votes_options() {
    	$postid = $_POST['postid'];
    	$ip = $_POST['ip'];
    	if (!wp_verify_nonce($_POST['nonce'], 'voting_nonce_'.$postid))
    	$voter_ips = get_post_meta($postid, "voter_ips", true);
    	if(!empty($voter_ips) && in_array($ip, $voter_ips)) {
    		echo "null";
    	} else {
    		$voter_ips[] = $ip;
    		update_post_meta($postid, "voter_ips", $voter_ips);
    	$current_votes = get_post_meta($postid, "votes", true);
    	$new_votes = intval($current_votes) + 1;
    	update_post_meta($postid, "votes", $new_votes);
    	$return = $new_votes>1 ? $new_votes : $new_votes;
    	echo $return;

    And here's how it's brought in:

    <div class="grid_row_1">
    	<div class="grid_col ingredients post-holder" data-direction="DESC" data-order="date">
    		<?php $count = 0; ?>
    		<?php if (have_posts()) : ?>
    		<?php query_posts('posts_per_page=15&post_type=ingredient&paged='.$paged); while ( have_posts() ) : the_post(); ?>
    		foreach($ingredient_images as $meta_box) {
    		$data = get_post_meta($post->ID, 'ingredient-images', true);
    			case 'ingredient_thumb': $feature_thumb = $data[ $meta_box[ 'name' ] ]; break;
    			case 'ingredient_status': $feature_thumb_show = $data[ $meta_box[ 'name' ] ]; break;
    			case 1: $type='suggested'; break;
    			case 2: $type='accepted'; break;
    			case 3: $type='featured'; break;
    		$theDate= get_the_date( 'o-n-j' );
    		$time = strtotime($theDate);
    		$one_week_ago = strtotime('-1 week');
    			case 0: echo '<div class="post one-quarter-sub-col-above-480 one-half-sub-col-at-480 first '.$type.'">'; 	   $count++; break;
    			case 1: echo '<div class="post one-quarter-sub-col-above-480 one-half-sub-col-at-480 last-at-480 '.$type.'">';  $count++; break;
    			case 2: echo '<div class="post one-quarter-sub-col-above-480 one-half-sub-col-at-480 first-at-480 '.$type.'">'; $count++; break;
    			case 3: echo '<div class="post one-quarter-sub-col-above-480 one-half-sub-col-at-480 last '.$type.'">'; 		   $count = 0; break;
    		$votes = get_post_meta($post->ID, "votes", true);
    		$votes = !empty($votes) ? $votes : "0";
    		$hasvoted = $_COOKIE['better_votes_'.$post->ID];
    		$hasvoted = explode(",", $hasvoted);
    		if(in_array($post->ID, $hasvoted)) {
    			$vtext = "VOTED";
    			$class = 'unvote-sm';
    		} else {
    			$ip = $_SERVER['REMOTE_ADDR'];
    			$voter_ips = get_post_meta($post->ID, "voter_ips", true);
    			if(!empty($voter_ips) && in_array($ip, $voter_ips)) {
    				$vtext = "VOTED";
    				$class = 'unvote-sm';
    			} else {
    				$vtext = "VOTE";
    				$class = 'vote-sm';
    		<?php if(function_exists('wp_nonce_field')) wp_nonce_field('voting_nonce_'.$post->ID.'', 'voting_nonce_'.$post->ID.''); ?>
    			<div class="bg-white pad-lr10 pad-t10 border-lightgrey margin-b10">
    				<div class="photo-wrapper ratio-16-9 text-white">
    					<?php if($feature_thumb_show!=3): ?>
    					<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/blank_landscape.gif"></a>
    					<div class="image-overlay full-width full-height align-center bg-lightblue">
    						<table class="layout-vert-center full-width full-height">
    							<tr><td><a class="header font-30 tk3 leading-tight" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></td></tr>
    					<?php else: ?>
    					<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/includes/timthumb.php?src=<?php echo $feature_thumb; ?>&w=220&h=130&a=t"></a>
    					<div class="image-overlay bottom bg-black bg-opaque-50 pad-5">
    						<a class="header font-30 tk3 leading-tight" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    					<?php endif; ?>
    					<?php if( $time > $one_week_ago ) {?>
    					<div class="image-overlay"><img src="<?php bloginfo('template_directory'); ?>/images/icon_new.png"></div>
    					<?php } ?>
    				<div class="clear"></div>
    				<div class="font-16 leading-medium">
    					<div class="one-half">
    						<a href="#" class="vote icon-text-link disp-block border-right-lightgrey pad-tb5 pad-r5 tk3" data-post="<?php echo $post->ID ?>">
    							<div class="vote-text pad-t5 float-left"><?php echo $vtext; ?></div>
    							<div class="float-right">
    								<div class="vote-count float-left text-medgrey pad-t5"><?php echo $votes; ?></div>
    								<span class="icon-holder float-left <?php echo $class; ?>"></span>

    Any help would be greatly appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic