Save search criteria per user and show on custom user page

admin2025-01-07  6

I have a property website with a custom search form for minimum and maximum square feet.

A registered user executes a search with a min(i.e. 150 sqft) and max(i.e. 300 sqft) select option value.

I managed already to store inside cookies the min and max values.

Then the user is able to click on a "save this search" button.

I would like to save those values inside the database and show them on each user's profile page (that I already created).

When the user goes to its profile page I'd like to have a list of all the saved searches.

I hope this makes sense.

Ideally the custom user page would look like this:

Saved Search 1: 150sq ft - 300 sq ft

Saved Search 2: 500sq ft - 800 sq ft

...

Is this possible? How would I do this?

I'm quite new at customising WordPress templates, I would really appreciate any help.

I have a property website with a custom search form for minimum and maximum square feet.

A registered user executes a search with a min(i.e. 150 sqft) and max(i.e. 300 sqft) select option value.

I managed already to store inside cookies the min and max values.

Then the user is able to click on a "save this search" button.

I would like to save those values inside the database and show them on each user's profile page (that I already created).

When the user goes to its profile page I'd like to have a list of all the saved searches.

I hope this makes sense.

Ideally the custom user page would look like this:

Saved Search 1: 150sq ft - 300 sq ft

Saved Search 2: 500sq ft - 800 sq ft

...

Is this possible? How would I do this?

I'm quite new at customising WordPress templates, I would really appreciate any help.

Share Improve this question edited Jun 16, 2015 at 17:20 Jeff asked Jun 16, 2015 at 16:16 JeffJeff 3692 gold badges5 silver badges13 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 0

Assuming that those users have accounts on your site (are subscribers, authors, or some other role), you can add custom fields to their profiles. The easiest way is to use a plugin, like Advanced Custom Fields (https://wordpress.org/plugins/advanced-custom-fields/).

The fields would be available in their profile pages, and you can add, and use in any template.

I would give you code examples, but their site seems to be down... I'll try to update the answer once it's up again.

Update: ACF could take care of creating the fields, and displaying them in the user profile page, and you can use add_user_meta to save them:

add_user_meta( $user_id, 'custom_field_name', $search);

If you don't want to use ACF, you can display the fields in the profile with custom code. Deleting the searches would be a bit harder, though, but doable.

Sumup:

Create a new post & save the search info as post meta-data, then reference it later by the post-id.

Create custom post type

Learn to Save post meta

Use wp_insert_post to save post & meta when search saved

Output in templates using conventional loops

This gives us a backend solution, that could tie-in to the data you've mentioned saving, a front-end solution might consist of adding the data to window.localStorage for later lookup & pre-population into the form inputs.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736254072a175.html

最新回复(0)