Skip Navigation

[Résolu] Can a parametric search be made using alphabet as selector for post title list

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How to make a parametric search like phone book, when you click on Letter it return all post title that start with the Letter chosen

Solution:
It is not possible with the

[wpv-filter-search-box]

https://toolset.com/forums/topic/can-a-parametric-search-be-made-using-alphabet-as-selector-for-post-title-list/#post-367498

What you can do is add a Custom field holding the First Letter of your Post Title for each Post.
https://toolset.com/documentation/user-guides/using-custom-fields/

A user provided a Custom Code solution, which is not supported by the Toolset Team, but might work on your end:
https://toolset.com/forums/topic/can-a-parametric-search-be-made-using-alphabet-as-selector-for-post-title-list/#post-369991

This support ticket is created Il y a 8 années et 2 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Marqué : 

This topic contains 5 réponses, has 2 voix.

Last updated by joshO Il y a 8 années et 2 mois.

Assisted by: Beda.

Auteur
Publications
#367426
Screen Shot 2016-02-16 at 10.54.04 PM.png

I am trying to: make a parametric search like phone book, when you click on Letter it return all post title that start with Letter.

Is there a way to add parameters or attributes for [wpv-filter-search-box] so that I could make one for each letter of alphabet when the letter is chosen the search defaults to the parameter.

I visited this URL:

I expected to see:

Instead, I got:

#367498

The [wpv-filter-search-box] is a Search box to type in characters and find the content related to it, in the Post Title and optionally in the Post Body.
https://toolset.com/documentation/views-shortcodes/#wpv-filter-search-box

It will not query the Title by a certain "order" (you can search for "A" and the query searches for it in the entire title)

That's a WordPress native Search Query which we do not modify.

You can also not Query the View Posts by Post Title, other then with the [wpv-filter-search-box].

What you can do is add a Custom field holding the First Letter of your Post Title for each Post.
https://toolset.com/documentation/user-guides/using-custom-fields/

That Custom Field can be used in the View Query filter or the Parametric Search.
https://toolset.com/documentation/user-guides/front-page-filters/
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#369383

Let try another approach. We created a CPT 'first-letter' for Type Company. We would like to update this field after parsing the titles first letter when saving CRED form.

We have been messing with this code we modified from your sample, so far, but cant get it to work. Please advise.

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form = company

if ($form_data['id']==705) {
$firstletter =get_post_meta($post_id, substr($title,0,1), true);
// echo($firstletter)
update_post_meta($post_ID, ‘wpcf_first_letter',$firstletter);

}
}

#369453

I looked at documentation https://toolset.com/documentation/user-guides/cred-api/#csd

Not updating database with value.

add_action('cred_save_data_705', 'save_data_for_form_with_id_705',10,2);
function save_data_for_form_with_id_705($post_id, $form_data)
{
$firstletter =get_post_meta($post_id, substr($title,0,1),false);
update_post_meta($post_ID,wpcf-first-letter,$firstletter);

}

#369687

I apologize the delay here

1. We created a CPT 'first-letter' for Type Company.

I assume you mean, you created a CF (Custom Field) not a CPT (Custom Post Type) for the Custom Post Type "Company", right?

2. We would like to update this field after parsing the titles first letter when saving CRED form.

You can do this.
The part of "parsing the titles first letter" will require custom code that I can not assist as per Company Policy, since it's not a feature of Toolset or our API.

3. We have been messing with this code we modified from your sample, so far, but cant get it to work. Please advise.

I modified your Code below in the parts of Toolset API and it's supported parts:

function my_save_data_action($post_id, $form_data) {
    // if a specific form = change the ID accordingly 
    if ($form_data['id']==705) {

    //To address a post_meta you will use get_post_meta() as in this syntax:
    //https://developer.wordpress.org/reference/functions/get_post_meta/
    //get_post_meta ( int $post_id, string $key = '', bool $single = false )
    /get_post_meta ( $post_id, 'wpcf-your-field', false);

    //This is your code
    $firstletter =get_post_meta($post_id, substr($title,0,1), true);
    // echo($firstletter)

    //You update the post_meta with this syntax:
    //https://developer.wordpress.org/reference/functions/update_post_meta/
    //update_post_meta ( int $post_id, string $meta_key, mixed $meta_value, mixed $prev_value = '' )
    //update_post_meta ( $post_id, 'wpcf-your-field-to-update, $value_to_update_with )
    update_post_meta($post_ID, 'wpcf_first_letter',$firstletter);

    }
}
add_action('cred_save_data', 'my_save_data_action',10,2);

What I do not understand from your above code is, it seems you store the Title of the Post in a Custom Field?

Because if you use the WordPress native title, you can not get it with get_post_meta()

You need to use get_the_title() as example
https://developer.wordpress.org/reference/functions/get_the_title/

Please let me know if you have further questions regarding the issue mentioned in this Thread

Thank you for your patience.

#369991

How to get Alphabet Listing when click on Letter , filters view on letter.

1. created custom field first-letter
2. Alpha listing - Added to View in Visual editor cell

 
<h4><a href="[wpv-bloginfo show='url']">ALL</a> | <a href="?first_letter=a">A </a><a href="?first_letter=b">B</a> <a href="?first_letter=c">C</a> <a href="?first_letter=d">D</a> <a href="?first_letter=e">E</a> <a href="?first_letter=f">F</a> <a href="?first_letter=g">G</a> <a href="?first_letter=h">H</a> <a href="?first_letter=i">I</a> <a href="?first_letter=j">J</a> <a href="?first_letter=k">K</a> <a href="?first_letter=l">L</a> <a href="?first_letter=m">M</a> <a href="?first_letter=n">N</a> <a href="?first_letter=o">O</a> <a href="?first_letter=p">P</a> <a href="?first_letter=q">Q</a> <a href="?first_letter=r">R</a> <a href="?first_letter=s">S</a> <a href="?first_letter=t">T</a> <a href="?first_letter=u">U</a> <a href="?first_letter=v">V</a> <a href="?first_letter=w">W</a> <a href="?first_letter=x">X</a> <a href="?first_letter=y">Y</a> <a href="?first_letter=z">Z</a></h4>

3. Add a unordered list view for Query Filter with
First Letter is a string equal to URL_PARAM(first_letter)

4. added code to child theme functions.php

 
/* *********************
Alphabet listing   add First letter of title when save to custom field wpcf-first-letter
*********************  */
add_action('cred_submit_complete', 'add_first_letter',10,2);
function add_first_letter($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==705)
    {
        $title = get_the_title();   
	$titlefirstletter = substr($title, 0, 1);	
            // add it to saved post meta 
      update_post_meta($post_id, 'wpcf-first-letter', $titlefirstletter);
    }
}
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.