Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Jacks89

    (@jacks89)

    Nevermind.

    I found a round about of doing it.

    Run 2 loop:
    1st loop is check if in_category of featured articles
    2nd loop is check if ! in_category of featured articles

    Thread Starter Jacks89

    (@jacks89)

    So you actually serialize the code before inserting to DB.

    Thanks for the tips that actually helped me optimized my code.

    Thread Starter Jacks89

    (@jacks89)

    Thanks for hint.

    I am not sure if I did it correctly but I managed to get it working.

    if ( function_exists( 'the_field' ) ) {
    		global $wpdb;
    
    		$result = $wpdb->get_results( "SELECT rating FROM $wpdb->acfsrf where user_id=".get_current_user_id()." AND meta_id=".get_the_ID() );
    		if ($result != NULL){
    			 function removeVote() {
    					global $wpdb;
    					//GET current user rating
    					$result2 = $wpdb->get_results( "SELECT rating FROM $wpdb->acfsrf where user_id=".get_current_user_id()." AND meta_id=".get_the_ID() );
    					$current_rate = ($result2[0]->rating);
    
    					//GET the current result and segregate result
    					$result3 = $wpdb->get_results( "SELECT meta_value FROM $wpdb->postmeta where meta_key='rate' AND post_id=".get_the_ID() );
    					$ratearray = explode(";", $result3[0]->meta_value);
    
    					//Remove d: and i: from string
    					$total_rate = str_replace("d:", "", $ratearray[1]);
    					$total_user = str_replace("i:", "", $ratearray[3]);
    
    					//Update the respective value
    					$updated_user = $total_user-1;
    					$updated_rate = (($total_rate * $total_user)-$current_rate)/($updated_user);
    
    					//convert value to string
    					$new_value = "$ratearray[0];d:$updated_rate;$ratearray[2];i:$updated_user;$ratearray[4]";
    
    					//Update table with user
    					$result4 = $wpdb->update($wpdb->postmeta , array('meta_value' => $new_value), array('meta_key' => 'rate', 'post_id' => get_the_ID()));
    
    					//remove the current user rate
    					$result5 = $wpdb->delete( $wpdb->acfsrf , array( 'user_id' => get_current_user_id(), 'meta_id' => get_the_ID()  ) );
    					if ($result5 && $result4){
    						wp_redirect( add_query_arg( array('vote_remove' => false), $_SERVER['REQUEST_URI']) );
    						exit;
    					}
    				}
    
    				if (isset($_GET['vote_remove'])) {
    					removeVote();
    				}
    				?>
    				<a href='index.php?vote_remove=true'>Remove your rate!</a>
    		<?php } else{
    	        $star_rating = get_field( 'field_55b60d9089739', get_the_ID());
    	        print_r($star_rating);
        	}
        }

    Thread Starter Jacks89

    (@jacks89)

    Additionally. Instead of changing the vote, I tried to remove it from database using the follow:

    if ( function_exists( 'the_field' ) ) {
    		global $wpdb;
    
    		$results = $wpdb->get_results( "SELECT rating FROM $wpdb->acfsrf where user_id=".get_current_user_id()." AND meta_id=".get_the_ID() );
    		if ($results != NULL){
    			 function removeVote() {
    					global $wpdb;
    					$results2 = $wpdb->delete( $wpdb->acfsrf , array( 'user_id' => get_current_user_id(), 'meta_id' => get_the_ID()  ) );
    					if ($results2){
    						echo "deleted successfully";
    					}
    				}
    
    				if (isset($_GET['vote_remove'])) {
    					removeVote();
    				}
    				?>
    				<a href='index.php?vote_remove=true'>Remove your rate!</a>
    		<?php } else{
    	        $star_rating = get_field( 'field_55b60d9089739', get_the_ID());
    	        print_r($star_rating);
        	}
        }

    I managed to remove the row from database. And the user can vote again. However the data persist. May I know where else do I have to remove aside from wp_acfsrf?

    Thank you.

    Thread Starter Jacks89

    (@jacks89)

    This is how I added the code

    <div id="slider1_container" style="position: relative; width: 720px;
            height: 480px; overflow: hidden;">
    
            <!-- Loading Screen -->
            <div u="loading" style="position: absolute; top: 0px; left: 0px;">
                <div style="filter: alpha(opacity=70); opacity:0.7; position: absolute; display: block;
                    background-color: #000; top: 0px; left: 0px;width: 100%;height:100%;">
                </div>
                <div style="position: absolute; display: block; background: url(https://egglove.sg/wp-content/themes/Orion/js/jssor/img/loading.gif) no-repeat center center;
                    top: 0px; left: 0px;width: 100%;height:100%;">
                </div>
            </div>
    
            <!-- Slides Container -->
            <div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width: 720px; height: 480px;
                overflow: hidden;">
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/01.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-01.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/02.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-02.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/03.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-03.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/04.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-04.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/05.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-05.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/06.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-06.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/07.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-07.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/08.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-08.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/09.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-09.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/10.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-10.jpg" />
                </div>
    
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/11.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-11.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/12.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-12.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/13.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-13.jpg" />
                </div>
                <div>
                    <img u="image" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/14.jpg" />
                    <img u="thumb" src="https://egglove.sg/wp-content/themes/Orion/js/jssor/img/travel/thumb-14.jpg" />
                </div>
            </div>
    
            <!-- thumbnail navigator container -->
            <div u="thumbnavigator" class="jssort07" style="width: 720px; height: 100px; left: 0px; bottom: 0px;">
                <!-- Thumbnail Item Skin Begin -->
                <div u="slides" style="cursor: default;">
                    <div u="prototype" class="p">
                        <div u="thumbnailtemplate" class="i"></div>
                        <div class="o"></div>
                    </div>
                </div>
    
                <!-- Arrow Left -->
                <span u="arrowleft" class="jssora11l" style="top: 123px; left: 8px;">
                </span>
                <!-- Arrow Right -->
                <span u="arrowright" class="jssora11r" style="top: 123px; right: 8px;">
                </span>
                <!--#endregion Arrow Navigator Skin End -->
            </div>
            <!--#endregion Thumbnail Navigator Skin End -->
            <a style="display: none" href="https://www.jssor.com">Bootstrap Slider</a>
            <!-- Trigger -->
        </div>

    I’m currently testing the slider from jssor. I don’t want to install the plugin since it will not be intuitive for the user.

Viewing 5 replies - 1 through 5 (of 5 total)