Hello, there's nothing exactly like this built-in to Views so it would require custom code using our PHP APIs. Another option is to create a custom taxonomy that includes one term for each letter A, B, C, etc., then apply the corresponding term to each post manually in wp-admin. Then you could create a View of posts filtered by the desired taxonomy term. The taxonomy approach is what I would recommend if you're not comfortable writing custom PHP code. If you're able to write PHP, I can show you how to use our Views Filter wpv_filter_query to modify the search query programmatically using your own custom code. https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Let me know if you'd like to discuss either of these approaches in more detail, and I can give you some more guidance.
Hi Christian,
i did it by myself as you required with taxonomy A, B, C ...
And that would work fine if I managed the website in the future.
But my client wants this to happen automatically, so they don’t have to think about so many things when creating a post.
So i prefer to do this with PHP.
I don't have a problem with PHP but im new in Toolset and how it's work.
This is my first project with Toolset so i need more time to learn where is things and how they works.
So yes please let's discuss second solution with query filters and PHP.
But my client wants this to happen automatically, so they don’t have to think about so many things when creating a post. So i prefer to do this with PHP.
Okay sure, this makes sense. If you're new to Toolset / WordPress in general you may not be aware how to add custom PHP code to a site. Child themes and custom code snippets are two common approaches to adding custom code.
- Add the code to a child theme's functions.php file. Normally you should not add custom code directly to a theme, since updating the theme in the future will delete your changes. Instead, create and implement a child theme. Updates to the parent theme will not override the changes in your child theme. More information about child themes: https://developer.wordpress.org/themes/advanced-topics/child-themes/
- Create a new custom code snippet in Toolset > Settings > Custom Code tab, and add your PHP code here. Set the snippet to run everywhere and be sure to activate it when you are finished coding. These code snippets are stored as files on your server outside of the Toolset plugin directories, and will not be deleted or modified when Toolset plugins are updated or deactivated.
$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));
I'm not a SQL expert, so I'm not really the best source of information about querying the database directly like this, but you can get the idea from this example. The $postids returned by this SQL query are then used to set the original $query's 'post__in' filter argument. More about post query filters here: https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters
The wpv_filter_query filter passes the manipulated post__in filter parameter along to the original query, the query continues, and results are generated. That's the general idea. If you need more information about how the wpv_filter_query filter works in the general request lifecycle, please let me know.
The second code you've sent is from our Blocks interface. In order to have the views interface you will need to enable the classic editor by going to Toolset -> Settings and scrolling to editing experience. From there you should see 3 options, select the 3rd option.
Once the page is saved you can refresh and you will now see the option Toolset->Views .
Hi, just checking in to see if you were able to resolve this one or if you needed some additional guidance. Let me know if you need anything else from support.