Skip Navigation

[Resolved] Creating A Custom Search Using Criteria From Two Types

This support ticket is created 5 years, 10 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
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 6 replies, has 2 voices.

Last updated by Christian Cox 5 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#912536

I am trying to: Get search results using variables from 2 sets of custom fields: one is a types called School and the other custom fields are assigned to Woo Products.

Link to a page where the issue can be seen: hidden link

I expected to see: I want to select the school and gender and see the appropriate results.

Instead, I got: No results can be found. If I choose the school name (which is part of the custom type I created), it will work, but if I choose school name + gender I get no results.

#912630

Hi, it sounds like you would like to filter a View of your custom post type (I think it's Schools) by a field in a different post type, Products. Unfortunately Users cannot filter a View of post type A by a field in post type B, even if the post types are related using a Toolset Relationship. Can you explain more about how Products and Schools are related, and why the "gender" field is applied to Products instead of Schools? I might be able to help figure something else out.

#913463

Thanks for the reply.

I have most of it figured out at this point, but I have a few remaining questions:

The first relates to the results in a parametric search. So basically what I did was create a new custom type called "schools" and some custom fields: school name, school logo, school category, genders, and grades. In admin, both grades and gender are multi-check boxes and on the public side, they are dropdowns.

So what happens is when someone chooses a school name, gender, and grade, those fields autopopulate the woo products shortcode so that the results will only show products that have categories that meet all three of those qualifiers.

So far so good.

The last few glitches in the matrix are:

1) I want to store the "logo" field in a session-like fashion or pass as a GET so the product detail can include the school's logo. I only want to pass the URL string of the logo (url="true"). I would also like to pass "school name" as well, but I figure once you give me the best way to pass the logo, I can pass along the school name in the same fashion. Once i get that, then I will create a custom single page layout in Views to include the dynamic logo and school name above the product details.

2) I want the client to upload the data via a CSV. We typically use WP-All Import for such tasks, but I noticed when I tried to export a "template" to give them using WP-All Export, the types, custom fields were blank. So I just used the WordPress export feature and downloaded by custom post type. I noticed the data for the multi-checkboxes looks serialized, which would be difficult for an end user to interpret:

<wp:meta_value><![CDATA[a:2:{s:64:"wpcf-fields-checkboxes-option-d068de1699f70afff5b023acaf86c585-1";a:1:{i:0;s:4:"Boys";}s:64:"wpcf-fields-checkboxes-option-a714e02bd080b0044adb2fe28f28637b-1";a:1:{i:0;s:5:"Girls";}}]]></wp:meta_value>

I was hoping these vars would be independently stored in the Options table or something like that. So, should I change the method of inputting from Multiple Checkboxes to something unserialized (and if so what) or do you have some magic where I can import data from a CSV without going through some PHP gymnastics and have it in common language for the client? I would prefer the client has several columns in their CSV, each with a separate grade listed.

#913572

I resolved the serialized data portion of my question. Now I am down to storing a types var in a session or something like that. Any help is appreciated.

#913628

Not sure I understand how you determine which logo you want to store, but if you know the post ID where the logo is stored as a custom field, then you can use the native WP method get_post_meta:

$logo_url = get_post_meta( $post_id, 'wpcf-logoslug', true);

Replace wpcf-logoslug with the actual slug of your custom field, using the wpcf- prefix. So if your logo custom field has a slug in wp-admin like "school-logo" then the text here should be 'wpcf-school-logo'.

Or, you can set a custom field in the User's profile that stores the value of the logo URL. If I could see the system in action I might get a clearer idea and have a better solution. URL?

#913650

Its a little tricky to explain, but let me give it a shot. I create a parametric search view. The search is based on a custom type that includes school info, such as school name and school logo in custom types fields. When a person selects the school and hits search, the logo is in a custom view on the search results page.

I need to translate that specific logo to other pages. So on the search results page. We use the WooCommerce Shortcode to show products. When they click on the product, I want the logo to be available on the product detail page, which means I need a way to store the image URL.

#914419

Okay I see what you mean. You want the Product detail page to include an image based on which Search Result the User navigated from. Setting a session variable may work, but you'd have to figure out how to do that when the User clicks a link in the Search Results page. I can help you get a custom field value using PHP and the post ID, but setting that value upon clicking a link is outside of the scope of support we provide here.

One other thing I can think of that doesn't require custom code is to add a school ID URL parameter to the Product page link in the Search Results, like this: http://yoursite.com/product/your-product-slug?school=12345

Then use that numeric ID to get the logo from the School post on the Product page. We offer the wpv-search-term shortcode, which will help you access URL parameters and use them in your Types field shortcodes, like this:

[types field="school-logo" id="[wpv-search-term param='school']"][/types]

You'll have to use conditional HTML to handle the case where someone does not come directly from the Search Results.

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