Skip Navigation

[Closed] Update the values of custom fields in the Custom Post types dynamically?

This support ticket is created 10 years, 1 month 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.

This topic contains 2 replies, has 3 voices.

Last updated by Juan 10 years, 1 month ago.

Assisted by: Bigul.

Author
Posts
#148146

I have a custom field in my custom post type. It is basically the number of vote counts and number of post hits. I wish to know how can i update the values of the custom fields dynamically.

For the vote count i have created a form using CRED and want to update the value from there and for the number of hits i have searched a lot of plugins but all of them store the results in the database and not in the custom fields (and i want to use wp-types & achieve it, so how do i use any of the plugins and have fetch from the database or please suggest a plugin which stores number of hits in the custom fields).

Also i need to dynamically re-order the listing of my posts based on these custom fields, i.e.e by default they will be ordered by the Date (which is my custom selection in the Ordering in the views). But i have 2 buttons on my page for ordering(Most Read & Most Voted) on click of which the posts need to be re-ordered according to the custom fields of Number of Votes or Number of Hits.

#148864

Bigul
Supporter

Dear Reiner,

We are looking for a possible solution and get back to you as soon as possible. Please wait.

--
With Regards

Bigul

#148909

Juan
Supporter

Timezone: Europe/Madrid (GMT+01:00)

Hi Reiner.

This is Juan, from Views dev team.

I understand that you have two main issues: one about the posts hits and other about reordering a View based on the values of two fields.

For the first issue about recording posts hits, I do not know about any good solution for this. Sorry to say.

About sorting the View by the value of the fields, this is kind of possible, but there are some "ifs" and some things that you need to check (or I need to see).

First of all, we are talking about numeric fields. WordPress does allow for sorting by a numeric field, but you need to specify it's numeric when you run the query. If you set those fields using Types and they are set to be numerical,we handle it. So the first question is: are those fields created in Types? If they are not, sorting by them can be done but:
- they won't have a natural order. Think of 1 -> 11 -> 2instead of 1 -> 2 -> 11.
- the sorting might be more complex to get, but still doable

In addition to know if the fields are created using Types, there is another parameter that is important to do what you want. Every time a View is rendered, a number is associated to it. This number gets appended to some elements in the layout and/or other HTML rendered parts of the View, in order to have a different element per every View displayed in the page. We need to know that number, and the easier way is if I can take a look at the page itself, so a link would be much appreciated.

Once we know this all,we can set a custom link that will render your View ordered by your custom fields. If the page holding the View is right now example.com/my-page/ it will be something like example.com/my-page/?wpv_column_sort_id=custom-field-xxxx&wpv_column_sort_dir=asc&wpv_view_count=1

As you see, this is doable but not trivial, so if you want we can start with it right away 🙂

Regards,
Juan de Paco

The topic ‘[Closed] Update the values of custom fields in the Custom Post types dynamically?’ is closed to new replies.