Skip Navigation

[Resolved] Filtering Artist by selecting the first letter of the title

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

Problem:
How to build glossary (a to z) filter using view

Solution:
To build view with glossary filter, you need two views. You should add A-Z character as taxonomy terms by creating new alphabet taxonomy to display the A-Z character filter. You need another view to display posts belongs to the character.

You can find proposed solution with the following reply:
=> https://toolset.com/forums/topic/filtering-artist-by-selecting-the-first-letter-of-the-title/#post-602852

Relevant Documentation:

This support ticket is created 6 years, 11 months 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by Cesar 6 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#602656

Hi,

I need to filter my artist CPT by name.
I would like to display all the artist whose Name start with the letter B and be able to click into that letter A,B,C,D... and display just those Artist who's Post Title start with the selected letter

Can this be done using Query Filter --> Search Filter ???
How can a call a custom search from a link ???

Thanks

#602852

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Yes, its possible but needs some custom programming and few steps needs to follow:

1)
Create a taxonomy namely "alphabets" and add A to Z as terms.

2)
Now create a taxonomy view listing "alphabets" taxonomy terms. The loop output section should look like this:

[wpv-layout-start]
    [wpv-items-found]
    <a href="[current_url]">All</a>
    <!-- wpv-loop-start -->
        <wpv-loop>
            <a href="?wpvalphabet=[wpv-taxonomy-title]">[wpv-taxonomy-title]</a>
        </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
        <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
    [/wpv-no-items-found]
[wpv-layout-end]

Add following code to your current themes funcitons.php file

add_shortcode( 'current_url', function(){
  
    $request = $_SERVER['HTTP_HOST'].strtok($_SERVER["REQUEST_URI"],'?');
    $protocol = '<em><u>hidden link</u></em>';
  
    if ( isset($_SERVER['HTTPS']) ) {
        $protocol = '<em><u>hidden link</u></em>';
    }
  
    return $protocol . $request;
} );

3)
Now create another view for which you want to display your posts:
-- Add following code to your loop output editor

[wpv-layout-start]
[wpv-view name="alphabet-terms"]
[wpv-items-found]
<!-- wpv-loop-start -->
        <wpv-loop>
            <h3>[wpv-post-link]</h3>
        </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
        <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
    [/wpv-no-items-found]
[wpv-layout-end]

-- Add following code to your current theme's functions.php file:

add_filter('wpv_filter_query', 'func_filter_by_title', 10, 2);
function func_filter_by_title($query, $setting) {

global $wpdb;
    
if($setting['view_id'] == 9999) {
		
		if(isset($_GET['wpvalphabet']) and $_GET['wpvalphabet']!='' ){
			
			
			$first_char = $_GET['wpvalphabet'];
			$postids = $wpdb->get_col($wpdb->prepare("SELECT      ID
														FROM        $wpdb->posts
														WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
														AND post_type = '".$query['post_type'][0]."'
														AND post_status = 'publish'
														ORDER BY    $wpdb->posts.post_title",$first_char)); 
														
		          $query['post__in'] = $postids;
                  }
  }
return $query;
}

Where:
-- Replace '9999' with your original view ID (i.e. ID of view "view-show-posts-filter-by-title")

4)
Now, Create a new page and Add view "view-show-posts-filter-by-title" to display the view with results.

More info:
=> https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/

#605368

Hi,

The solution is working perfectly and you are awesome for giving me so much gold. I've learned a lot about how to use toolset 😉 Thanks

The only part that is not working is the wpv-post-link shortcode. Is always redirecting to the https url.
Any idea why?

Thanks

#605375

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to know that solution working for you and pleasure to help you. May I kindly ask you to open a new ticket for your each new question.

This will help other users searching on the forum. Thank you for understanding.

#605382

Is not a new issue, is part of the code you provided

add_shortcode( 'current_url', function(){
   
    $request = $_SERVER['HTTP_HOST'].strtok($_SERVER["REQUEST_URI"],'?');
    $protocol = '<em><u>hidden link</u></em>';
   
    if ( isset($_SERVER['HTTPS']) ) {
        $protocol = '<em><u>hidden link</u></em>';
    }
   
    return $protocol . $request;
} );

protocol is always https

#605384

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please share problem URL?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#605385

Is a local site, never mind