• baga

    (@baga)


    Hello I’ve found this topic on your support forum:

    Okay well is there a way using the “uwpqsf_result_temp” hook to have one filter form, and have the results output to separate divs (want to use ajax)? Each div having its own results styled in a unique way. ONE form TWO different looking results on the same page

    Your answer:

    It is possible with the hook. It depends how you play with your codes. Eg, put the result in a placeholder and then echo it in the way you like in different div.

    Could you please provide some example codes? I’d like to display the results in a list and on a Google Map on the same page using ajax.

    Thanks

    https://www.ads-software.com/plugins/ultimate-wp-query-search-filter/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author TC.K

    (@wp_dummy)

    It’s all about php.
    But if you want to display in google map, it will be more complicated. It’s involve javascript.

    The ideas is like this:

    add_filter('uwpqsf_result_tempt', 'customize_output', '', 4);
    function customize_output($results , $arg, $id, $getdata ){
    	 // The Query
                $apiclass = new uwpqsfprocess();
                 $query = new WP_Query( $arg );
    		ob_start();	$result = '';
    			// The Loop
    
    		if ( $query->have_posts() ) {
    			while ( $query->have_posts() ) {
    				$query->the_post();global $post;
                                    $placeholder[] = array(
                                            'post_id' => $post->ID,
                                            'title' => $post->post_title,
                                            //and other data you needed, you can get it from the post object.
                                     );
    			}
                         //you can manipulate the data in the $placeholder here.
                         foreach($placeholder as $key=>$val){
                              //put the list here.
                          }
                          //if you want to put it in gmap, may be you can manipulate the placeholder data again here.
                          foreach($placeholder as $key=>$val){
                                   //blah blah blah
                            }
                            echo  $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id, $getdata);
    		 } else {
    					 echo  'no post found';
    				}
    				/* Restore original Post Data */
    				wp_reset_postdata();
    
    		$results = ob_get_clean();
    			return $results;
    }
    Thread Starter baga

    (@baga)

    Thank you very much TC.K!
    Tomorrow morning I’m gonna look into it.

    Thread Starter baga

    (@baga)

    I can’t get it to work… My knowledge of PHP is too poor ??
    This was my previous code which was working perfectly:

    <?php
    add_filter('uwpqsf_result_tempt', 'customize_output', '', 4);
    function customize_output($results , $arg, $id, $getdata ){
    // The Query
    $apiclass = new uwpqsfprocess();
    $query = new WP_Query( $arg );
    ob_start();	$result = '';
    // The Loop
    if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
    $query->the_post();
    global $post;
    global $wpdb;
    $attachment_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_status = 'inherit' AND post_type='attachment' LIMIT 1");
    $img = wp_get_attachment_url($attachment_id);
    $telefono = get_post_meta(get_the_ID(), 'Telefono', true);
    ?>
    <a href="<?php the_permalink(); ?>">
    <img src="<?php echo wp_get_attachment_url($attachment_id); ?>" alt="" />
    <h3><?php the_title(); ?></h3>
    <p><?php echo $telefono; ?></small></p>
    </a>
    <?php
    }
    echo  $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id, $getdata);
    } else {
    echo  'no post found';
    }
    /* Restore original Post Data */
    wp_reset_postdata();
    
    $results = ob_get_clean();
    return $results;
    }
    ?>

    Now I’ve tried something like this but without success even without trying to implement the maps:

    <?php
    add_filter('uwpqsf_result_tempt', 'customize_output', '', 4);
    function customize_output($results , $arg, $id, $getdata ){
    // The Query
    $apiclass = new uwpqsfprocess();
    $query = new WP_Query( $arg );
    ob_start();	$result = '';
    // The Loop
    if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
    $query->the_post();
    global $post;
    global $wpdb;
    $attachment_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_status = 'inherit' AND post_type='attachment' LIMIT 1");
    $img = wp_get_attachment_url($attachment_id);
    $telefono = get_post_meta(get_the_ID(), 'Telefono', true);
    $placeholder[] = array(
    'post_id' => $post->ID,
    'title' => $post->post_title,
    //and other data you needed, you can get it from the post object.
    );
    $i++;
    }
    //you can manipulate the data in the $placeholder here.
    foreach($placeholder as $key=>$val){
    //put the list here.
    ?>
    <a href="<?php the_permalink(); ?>">
    <img src="<?php echo wp_get_attachment_url($attachment_id); ?>" alt="" />
    <h3><?php the_title(); ?></h3>
    <p><?php echo $telefono; ?></small></p>
    </a>
    <?php
    }
    //if you want to put it in gmap, may be you can manipulate the placeholder data again here.
    foreach($placeholder as $key=>$val){
    //blah blah blah
    }
    echo  $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id, $getdata);
    } else {
    echo  'no post found';
    }
    /* Restore original Post Data */
    wp_reset_postdata();
    
    $results = ob_get_clean();
    return $results;
    }
    ?>

    Where am I wrong?

    Plugin Author TC.K

    (@wp_dummy)

    Don’t sure what you want to do. You can’t simply copy and paste into your code. The codes is only an example to show you how it can be done.

    Thread Starter baga

    (@baga)

    I’d like to show the results in two different divs on the same page but couldn’t do it with the code you sent me yesterday.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Output results to separate divs’ is closed to new replies.