Skip Navigation

[Resolved] Recreating a form that was created in Access

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 24 replies, has 3 voices.

Last updated by christopherB-10 1 year, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#2551375

The only issue with moving the category into the Tuners type is that the types of parts can be different for every platform. Tuner A may have 3 types of parts for Platform A, but also 2 types for Platform B, and all types for Platform C.

I feel like there should be a way to filter duplicates out of the results. I'm definitely not seeing any options though.

Any other ideas I can try?

#2551487

Unfortunately, it is expected result, there isn't such kind of built-in option within Toolset plugins.

You might consider to use custom codes to remove the duplicated items, for example, after submit the custom search form, use action hook "wpv-before-display-post" to trigger a custom PHP function:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv-display-post

In this custom PHP function,
1) get all intermediatory post IDs from view result
2) Use above post IDs to get all related Tuner post IDs,
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
And remove those duplicated items.

#2552299

Hmm...custom codes might be a little beyond me. Maybe I'll simplify the page a little.

Last question related to this topic. Is there a way to change how the search fields display? As an example, if I use single field searches, I can place them next to each other, like this:

Make \/ Model \/ Platform \/

instead of:

Make \/
Model \/
Platform \/

I do want it to show up vertically when viewed on a mobile device.

Is there a way change the way they're displayed on the test site?

Thanks for all of the help!

#2553415

For the new question "show up vertically", you can follow our document to add some custom CSS codes into the view block, for example:

.wpv-custom-search-filter-label-top .form-group {
    display: inline-flex;
}

More help:
https://toolset.com/course-lesson/adding-custom-css-to-templates-archives-and-views/#steps-for-adding-css-to-a-view

#2557299

So I noticed this last line of code worked on your site, but it didn't work on mine. That's probably because it's referencing fields that aren't in my site right? so I'd have to edit it to match what fields are on my site for it to perform the edit?

#2557733

Actually, I have yet another question. Is there someone here that will work with me to create the site I hoped for? I have an image of what I think it should be in my head, and I seem to get in the ballpark, but never quite there. I'd like help with the code you mentioned above to remove the duplicates and recreate the form.

#2557847

Can you reproduce the same problem in a test site, and share the test website credentials in below private message box, also point out the problem page URLs.

I can setup a demo for you.

#2558431

Hi there.

I just added a bit of sample data from my site into your sandbox (hidden link) and I was able to recreate the issues. There are 2:

1) duplicates. I know you mentioned before some custom PHP code to remove the duplicates, but I don't know anything about PHP so I can't follow what you're saying. Maybe you can test it and see if there are other ways to do it? A search brings up a couple of previous tickets entered for the same issue, but I tried their code and it doesn't work for my site. Assuming it's because it's looking for pages/posts I don't have. Topics I looked at for this:

https://toolset.com/forums/topic/how-to-remove-duplicates-in-multi-relationship-views/

2) On the editing page, when I use the CSS to change it to horizontal instead of vertical, it changes the edit page, but not the preview. I was able to duplicate this on your sandbox as well. However, I remembered there are themes that are recommended for toolset, so I changed the theme from Twenty Twenty Two to Astra. This fixed that issue. However, it's pretty hard to style this field as it seems to be treated as one field instead of 3 individuals. Is there a way to put this field in a grid so that it lines up with other grids on the page, or a way to better style it (give it some space in between, etc)?

2a) is there a way to get other search fields inline with the Makes/Models/Platforms fields? I'd like to put the Categories field next to everything else?

2b) Is there a way for it to be horizontal for desktop and vertical for tablet and mobile devices? I'd like it to be this on desktop:

Make\/ Model\/ Platform\/ Category\/

and this on tablet/mobile:

Make\/
Model\/
Platform\/
Category\/

Thanks again for all of the help.

-Christopher
kazesupra@gmail.com

New threads created by Luo Yang and linked to this one are listed below:

https://toolset.com/forums/topic/style-relationship-search-form/

#2558461

Q1) I have setup a demo in the test site, here are the detail steps:
1) Add a custom code snippet "remove-duplicates":
hidden link

function remove_duplicates_query( $query, $view_settings, $view_id ) {
    $relationship_slug = 'platform-tuner'; // here replace platform-tuner with many-to-many relationship slug
  	$viewid = 105; // here replace 105 with the view ID of your website
    if ( $view_id == $viewid && !empty( $query->posts ) ) { 
      $res = array();
      $arr = array();
      foreach($query->posts as $key => $post){
      	$post_id = $post->ID; //intermediatory post ID
        $tuner_id = toolset_get_related_posts($post_id, $relationship_slug, [
            'query_by_role' => 'intermediary', 
            'role_to_return' => 'child',
            'return' => 'post_id'
        ]); 
        if(isset($tuner_id[0]) && !in_array($tuner_id[0], $arr)){ 
        	$arr[] = $tuner_id[0];
        	$res[] = $post;
        }
      }
      $query->posts = $res;
    }
    return $query;
}

Test it in frontend:
hidden link
It works fine.

More helps:
https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

According to our support policy, we prefer one ticket one question, for other tickets, please check the new thread here:
https://toolset.com/forums/topic/style-relationship-search-form/

#2558697

After a couple of attempts, I was able to get the code added and working flawlessly on my site. Thank you so much for all of the help and patience with this request.