WordPress.org

Forums

Ajax WP Query Search Filter
[resolved] Costumize result template (30 posts)

  1. Aldo
    Member
    Posted 2 years ago #

    Hello

    Is there a way to customize or create for each search form an own results template?

    Thanks,
    Aldo

    http://wordpress.org/extend/plugins/ajax-wp-query-search-filter/

  2. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    Yes, it is possible, Look for the ajax_wpqsf_reoutput() filter hook.

  3. Aldo
    Member
    Posted 2 years ago #

    How can I customize the pagination, any hook for this?

  4. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    Yes,
    There is a filter ajwpqsf_pagination for this, please goto /classes/ajwpqsf-misc-class.php in function ajax_pagination for how to use it. Basically you are only allowed to change the design of the pagination, other thing have to be changed carefully because some of the attribute is used for javascript ajax called, eg. <a id=''.... the id is use for the passing page to ajax call.

  5. Aldo
    Member
    Posted 2 years ago #

    But how do I use it in combination with ajax_wpqsf_reoutput()?
    Because the pagination is not showed at all.

  6. MrCarlLister
    Member
    Posted 2 years ago #

    I have a couple of questions around this discussion.

    Am I right in thinking that using the ajax_wpqsf_reoutput() filter hook will replace the query as well as the layout?

    Is there a way to just change the layout without changing the query argument?

    Cheers,

    Carl

  7. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    @Aldo,
    You will need to call the function again when you combine with ajax_wpqsf_reoutput() filter. Eg.

    $apiclass = new ajaxwpqsfclass();
    //and before end while loop:
    $apiclass->ajax_pagination($pagenumber,$query->max_num_pages, 4, $id);

    @MrCarlLister,
    Sure you can,just don't change anything on the argument, but change the layout on your result loop.

  8. Aldo
    Member
    Posted 2 years ago #

    Do I call the function in the customize_output filter?

  9. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    Yes, in your customize output filter.

  10. MrCarlLister
    Member
    Posted 2 years ago #

    @TC.K,

    I'm not sure what you mean (I'm not that experienced with hooks).

    Basically, I've put the hook into a function like so

    add_action ( 'ajax_wpqsf_reoutput', 'wpqsf_reoutput');
    
    function wpqsf_reoutput($results, $arg) {
    $html = '';
    
    	$html .= '<article><header class="entry-header">'.get_the_post_thumbnail().'';
    	$html .= '<h1 class="entry-title"><a href="'.get_permalink().'" rel="bookmark">'.get_the_title().'</a></h1>';
    	$html .= '</header>';
    	$html .= '<div class="entry-summary">'.get_the_excerpt().'</div></article>';
    
    return $html;
    }

    However, I seem to only be getting the last result when it's displayed - I've tried foreach loop but to no joy.

    Any help would be great!

    Cheers,

  11. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    @MrCarlLister,
    You did not pass the $arg in the wp_query class.
    To use it, eg:

    add_filter('ajax_wpqsf_reoutput','wpqsf_reoutput','',2);
    function ajax_result($result, $arg ){
    		   $apiclass = new ajaxwpqsfclass();
    		  // The Query
    			$query = new WP_Query( $arg );
    			$html ='';
    			// The Loop
    		if ( $query->have_posts() ) {
    			$html .= '<h1>'.__('Search Results :', 'AjWPQSF' ).'</h1>';
    			while ( $query->have_posts() ) { $query->the_post();
    //here where you customize your layout					$html .= '<article><header class="entry-header">'.get_the_post_thumbnail().'';
    					$html .= '<h1 class="entry-title"><a href="'.get_permalink().'" rel="bookmark">'.get_the_title().'</a></h1>';
    					$html .= '</header>';
    					$html .= '<div class="entry-summary">'.get_the_excerpt().'</div></article>';
    
    			}
    
    			$html .= $apiclass->ajax_pagination($pagenumber,$query->max_num_pages, 4, $id);
    		 } else {
    					$html .= __( 'Nothing Found', 'AjWPQSF' );
    				}
    				/* Restore original Post Data */
    				wp_reset_postdata();
    
    			return $html;
    
    	   }
  12. Aldo
    Member
    Posted 2 years ago #

    @TC.K,

    If i place
    $apiclass->ajax_pagination($pagenumber,$query->max_num_pages, 4, $id);
    before the end while loop I get the pagination on each entry.

    When I place it outside, I get the pagination, but clicking on a number does not change the page. It loads, but no change.

    EDIT: Pagination changes, but the class "pagicurrent" remains at the first page.

  13. MrCarlLister
    Member
    Posted 2 years ago #

    Yeah I'm getting the same pagination issue as @Aldo.

    Pagination changes, but the class "pagicurrent" remains at the first page.

  14. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    Oh...try to replace the $pagenumber on the ajax_pagination() with $arg['paged'].

  15. Aldo
    Member
    Posted 2 years ago #

    Still not changing the class "pagicurrent"

  16. MrCarlLister
    Member
    Posted 2 years ago #

    Worked for me!

    @Aldo your code should look something like this:

    add_filter('ajax_wpqsf_reoutput','wpqsf_reoutput','',2);
    
    function wpqsf_reoutput($result, $arg ){
    		   $apiclass = new ajaxwpqsfclass();
    		  // The Query
    			$query = new WP_Query( $arg );
    			$html ='';
    			// The Loop
    		if ( $query->have_posts() ) {
    			while ( $query->have_posts() ) {
    			$query->the_post();
    
    					$html .= '<div class="grid_container" style="padding-bottom: 20px;">';
    					$html .= '<a href="'.get_permalink().'" class="grid hall_of_fame" title="">'.get_the_post_thumbnail($eh,'hero_secondary').'<span></span><p>VIEW PROJECT <span class="hof_more"></span></p></a>';
    					$html .= '<h5><a href="'.get_permalink().'" rel="bookmark">'.get_the_title().'<span class="more"> </span></a></h5>';
    					$html .= '</div>';
    
    			}
    
    			$html .= $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id);
    		 } else {
    					$html .= __( 'Nothing Found', 'AjWPQSF' );
    				}
    				/* Restore original Post Data */
    				wp_reset_postdata();
    
    			return $html;
    
    	   }
  17. MrCarlLister
    Member
    Posted 2 years ago #

    On the topic of pagination; I'm looking to replace pagination with an 'infinite scroll' type thing so that instead of manually selecting a page to scroll to you'd just click 'load more' and it would load the next page beneath/as an addition to the original results.

    Any idea where I'd start with that?

    Cheers

  18. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    Yes, you can but there are lot more works you have to do.

    Things you have to do is pretty much on javascript and ajax called. I can't tell you how, you have to google it.

    Once you have the scrolling working (in js), now you have to bind this event to the ajax that handle the event. The ajax action function is awpqsf_ajax().

  19. Aldo
    Member
    Posted 2 years ago #

    Thanks, but still not changing the class "pagicurrent", where else could I look?

  20. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    Can you tell me what you trying to do?

  21. Aldo
    Member
    Posted 2 years ago #

    For some reason my "pagicurrent" class gets not changed to the according page when paginating.

    This is my code:

    function customize_output($results , $args){
    	$apiclass = new ajaxwpqsfclass();
    	 // The Query
    			$query = new WP_Query( $args );
    			$html = '';
    		//ob_start();	$results ='';
    			// The Loop
    		if ( $query->have_posts() ) {
    
    			while ( $query->have_posts() ) {
    				$query->the_post();
    
    				$html .= '<tr>';
    				$html .= '	<td><a href="'.get_permalink().'" class="name">'.get_the_title().'</a><span class="subtext">'. get_field('firma') .'</span></td>';
    				$html .= '	<td>';
    
    				$terms = get_the_terms( $post->ID, 'typ' );
                                    	if ( $terms && ! is_wp_error( $terms ) ) :
    										$type_links = array();
    
    										foreach ( $terms as $term ) {
    											$type_links[] = $term->name;
    										}
    										$types = join( ", ", $type_links );
    										$html .= $types;
    									endif;
    
    				$html .= '	</td>';
    
    				$html .= '	<td>';
    					$contact_person = get_field('ansprechsperson');
                        if (is_array($contact_person)) {
    	                	$html .= $contact_person["user_firstname"] . ' ' . $contact_person["user_lastname"];
                         } else {
                            $user = get_user_by( 'id', get_field('ansprechsperson') );
    						$html .= $user->first_name . ' ' . $user->last_name;
                          }
                    $html .= '	</td>';
    
    				$html .= '	<td class="align-right">';
                    $html .= '		<a href="#">'. get_field('e-mail') . '</a>';
                    $html .= '	</td>';
    				$html .= '</tr>';
    
    			}
    
    			$html .= $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id);
    
    		 } else {
    					 $html .=  'No post found';
    				}
    				/* Restore original Post Data */
    				wp_reset_postdata();
    
    			return $html;
    }
  22. Aldo
    Member
    Posted 2 years ago #

    One more question regarding the output template:
    How can I retrieve the search form ID in ajax_wpqsf_reoutput?

    EDIT: Could this be related to the "pagicurrent" issue?
    $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id) requires $id, but there is none in the ajax_wpqsf_reoutput filter.

  23. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    Did the pagination work correctly?

    The $id is the id of the the search form. I put it there for conditional check in case there are more then one search forms at the page. and user can customise the result accordingly.

  24. Aldo
    Member
    Posted 2 years ago #

    Yes, pagination works, but "pagicurrent" is not set correctly. The first page is allway active.

    As of $id, I would like to use it in "ajax_wpqsf_reoutput" to set different outputs depending on the search form id. How can I retrieve this id?

  25. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    Weird. Can you try to use the pagination without the content first (remain the loop, just remove everything in while loop)? It is to see if it was your search content that causing the problem.

    For the $id, just use normal conditional check will do the job. For eg:
    in your while loop:

    if($id == '23') //23 is your form id.
    { blah blah blah}
    if($id == '12')
    { blah blah blah}

    Note that you should pass $id parameter to your function.

  26. Aldo
    Member
    Posted 2 years ago #

    Still no correct "pagicurrent".

    As of the $id, how do I pass it into the filter?

  27. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    Weird, how about the result without the filter?

    I just found out I haven't add the form id parameter in the filter. Wait for my next update, I will include it later.

    I also notice that there is a mistake in your filter function. The post id should be like this $query->post->ID, not $post->ID

  28. Aldo
    Member
    Posted 2 years ago #

    Without the filter, the result for "pagicurrent" is fine.
    Any idea what else could be the issue?

    And thanks for the $query->post->ID hint!

  29. TC.K
    Member
    Plugin Author

    Posted 2 years ago #

    Ok, found your problem. it should be $args['paged'] not $arg['paged'] in the pagination function. You missed the 's' in the variable $args.

  30. Aldo
    Member
    Posted 2 years ago #

    Great!
    Thanks a lot :-)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Ajax WP Query Search Filter
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.