Skip Navigation

[Resolved] Alphabetical and numeric search buttons

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to create a custom search View that filters the results by the first letter of the post title. I'm starting with the solution in this ticket: @https://toolset.com/forums/topic/help-with-custom-alphabetic-searchdisplay/

Solution: Modify the custom code in functions.php to match this:

function posts_where_first_letter( $where ) {
     remove_filter( 'posts_where', 'posts_where_first_letter');
     if (!empty($_GET['wpv_post_search'])) {
          $param = esc_sql($_GET['wpv_post_search']);
          $mod = esc_sql('%');
          $where = str_replace( "post_title LIKE '" . $mod . $param . $mod . "'", "post_title LIKE '" . $param . $mod . "'", $where );
     }
       
     return $where;
}

Relevant Documentation:
https://toolset.com/documentation/user-guides/front-page-filters/
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 14 replies, has 2 voices.

Last updated by kristenM 5 years, 12 months ago.

Assisted by: Christian Cox.

Author
Posts
#625301
searchsystem for RDK.PNG

Hi Support.

I need help understanding this supportticket: https://toolset.com/forums/topic/ so I can show filter-buttons as shown in this screenshot.

I'm totally new to Toolset and I need to know where to put those strings of code from scratch.

I hope that you can help me please. It's regarding the page hidden link

Thank you in advance and kind regards.

Kristen

#625401

Hi, I wasn't able to see a full link to the post you mentioned. Could you paste a link to that topic again here, or copy + paste the code you have a question about?

Typically there are 4 types of code we discuss here:
1. PHP code. This generally goes in your child theme's functions.php file.
2. JavaScript code. This generally goes in the JS panel of a View, or in Layout CSS & JS.
3. CSS code. This generally goes in the CSS panel of a View, Layout CSS & JS, or in Appearance > Customize > Additional CSS.
4. Markup including Toolset shortcodes. This goes many places, like a Visual Editor cell or a View's Loop Output editor, or the contents of a Post.

#625407

Hi Christian.

Thank you so much for answering so quickly - and I'm sorry for not delivering the correct link.

I believe that this is it: https://toolset.com/forums/topic/help-with-custom-alphabetic-searchdisplay/

I look forward hearing from you again.

Kind regards

Kristen

#625410

Beda gives step-by-step instructions here: https://toolset.com/forums/topic/help-with-custom-alphabetic-searchdisplay/#post-537018
These instructions describe where each code snippet should be placed, by name. Is there a specific location you are unable to find, or something that does not make sense?

#625412
Views - Loop Output Editor.PNG
Views - filter editor.PNG
Views - Filter and Loop Output Integration Editor.PNG

Hi again Christian.

I think the problem is that I'm so new to Toolset and I haven't got the idea of how it works yet.

I have followed #3 andcreated a View - but I'm not sure where to put the code strings.

I therefor has taken screenshots of my View and named them what each field is called. If you could tell me where to put the different pieces of code I will be very grateful.

Kind regards

Kristen

#625433

#3 goes in the Loop Output editor panel. In your image Views - Loop Output Editor.PNG, this editor panel appears to be "locked". You can click the "Loop Wizard" button to get a wizard-style experience, or you can click "Skip Wizard" to jump right into the code. Since you already have the code from Beda, click "Skip Wizard" to unlock the panel. Filter changes go in the Filter Editor panel. You probably will not make any changes in the Filter and Loop Output Integration editor panel.

Underneath the Loop Output Editor you can expand panels for JS and CSS. Step #6 tells you which code goes in each panel.
Some more basic information here:
https://toolset.com/documentation/user-guides/front-page-filters/

#625894

Hi Christian.

Thank you for your help so far. I have actually done most of the things in the tutorial and I have got this:

hidden link

I think the problem is in the 5th. point where it says:

Note that the wpv-filter-search-box and the wpv-filter-submit MUST be inserted by the GUI.
So you cannot just copy paste the above code but need to insert the Filters with the GUI, and then adapt so it looks like the above code.

You'll find it here: https://toolset.com/forums/topic/help-with-custom-alphabetic-searchdisplay/#post-537018

Can you help explaining to me how I insert the code (I think it is this part)

[wpv-filter-search-box output="bootstrap"]
</div>[wpv-filter-submit output="bootstrap"]

with the GUI? (I believe that the GUI is the User Interface but Iøm not sure)

Thank you in advance.

Kind Regards.

Kristen

#625896

Oh and by the way the order of the alphabetic search is in wrong order. It should be "1 A B C" but instead it is "1 C B A"

Maybe I have done something woring?

Kind regards

Kristen

#625970
Screen Shot 2018-03-18 at 11.25.43 AM.png
[wpv-filter-search-box output="bootstrap"]
[wpv-filter-submit output="bootstrap"]

To insert these fields with the GUI (the user interface), click the "Text Search" and "Submit Button" buttons above the Filter Editor panel.

Oh and by the way the order of the alphabetic search is in wrong order. It should be "1 A B C" but instead it is "1 C B A"
Please take a screenshot showing the search View in wp-admin and include it here with your next reply.

#628619

Hi again Christian.

I am SO sorry, that I have to write and bother you again - but I just can't seem to get it quite right.

I have now tried different kind of Views about the result but is only getting this: hidden link

I know that the problem probably is in point 4-8 in this support-article: https://toolset.com/forums/topic/help-with-custom-alphabetic-searchdisplay/#post-537018

I have modified functions.php so that it is using "$view_id = 357" instead of "$view_id = 8" and "udstiller" instead of "post"

Can you figure out what the problem is?

Thank you in advance.

Kind regards

Kristen

#628874

I'm not able to tell much by looking at the front-end of the site. It looks like you have the filters set up, and when I click a filter and click the submit button the URL updates. To be able to make more suggestions I would need access to wp-admin to see how you have things configured. If that's okay please provide login credentials in the private reply fields here.

#629255

Hi, please check now. I had to make a minor adjustment to the code snippet, because the % symbol was causing some issues:

function posts_where_first_letter( $where ) {
     remove_filter( 'posts_where', 'posts_where_first_letter');
     if (!empty($_GET['wpv_post_search'])) {
          $param = esc_sql($_GET['wpv_post_search']);
          $mod = esc_sql('%');
          $where = str_replace( "post_title LIKE '" . $mod . $param . $mod . "'", "post_title LIKE '" . $param . $mod . "'", $where );
     }
      
     return $where;
}
#630335

Hi Christian.

Thank you so very much for fixing this search-engine. I've been adjusting it a bit - just to get a feeling of how it works.

Is there any way that I can eliminate the searchbutton-function? I mean that when I click "A" in the alphabetic menu at the top it does the search immediately instead of first choosing the letter "A" and then manually pressing the search-button?

Another thing is the order of the letters and number. Right now it is: "Alle - A - B - C - 1 - U". Can it instead be "Alle - A - B - C - U - 1"?

Last thing: I have put a Post-excerpt in to the View-loop, but the More-tag (...Mere) doesn't get a link to the specific post. Se the post under the letter "U".

I'm very happy with the results you have made so far. I believe that this is going to be so fine!

Thank you for your help so far.

I wish you a pleasant day.

Kind regards.

Kristen

#630366

Is there any way that I can eliminate the searchbutton-function?
You can eliminate the search button by creating a list of links that include the correct URL parameters. If you would like to create a separate ticket to address this once the rest of the View is functioning as expected, we can discuss the modifications that would be required.

Another thing is the order of the letters and number. Right now it is: "Alle - A - B - C - 1 - U". Can it instead be "Alle - A - B - C - U - 1"?
Not exactly. You can specify the sorting order by editing this View: hidden link
In the section "Ordering", choose "Post title" to sort the list alphabetically. This will result in "Alle - 1 - A - B - C - U" and so on because numbers appear before letters in an alphabetical sort. Further customization of that sort order will require custom code.

I have put a Post-excerpt in to the View-loop, but the More-tag (...Mere) doesn't get a link to the specific post. Se the post under the letter "U".
Correct, the post excerpt shortcode "more" attribute does not create a link to the post. You could add one like this:

<div class="col-sm-8">[wpv-post-excerpt length="25" count="word" more="...<a href='[wpv-post-url]'>Mere</a>"]<br /></div>
#630378

Thank you so much for solving this Problem, Christian Cox.
You are so competent in finding a solution for a big problem.
Kind regards
Kristen

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.