I'm trying to avoid creating additional custom field for one of the posts, and was wondering if there is a way to query WP DB to retrieve the necessary data.
I have 3 types of posts: Events, Programs and Locations. On the event post type, there is a custom field for program it is related to. On the program post type, there is a custom field for location.
I'm looking for a query, that can add to the single-location.php document, which will retrieve all the events in that location, without the need to create an additional custom field.
My logic was: get me all the events and filter all the events, where the related program, has a related location, which is the title of this post.
Would it be possible?
Related
I created a custom object and i want to get all its existing records. Is there a way of doing that via the REST API? Seems like a very basic and simple operation but i couldn't find information about it anywhere.
As you say, it seems like a basic task, but in the reality, it is more complex indeed.
Unfortunately, the Get Custom Object endpoint (which is the only endpoint to fetch Custom Objects) requires the filterType and filterValues parameters to be present as well. Basically this means that you have to have some information about the queried objects beforehand.
Also, a further restriction is that the value of filterType can only be one of the “searchable” fields of the Custom Object, meaning that it has to be either a Link field or a Dedupe field. (These fields are listed under the searchableFields property in the response from the Describe Custom Objects endpoint.)
So as mentioned above, you have to know the values for at least one of the properties of your Custom Objects before you make the query.
With additional queries though, you can grab these required values.
Let's say, you have your Custom Object linked to the Lead Object, and the Link field is called Owner Email (with the REST API name being ownerEmail) which links to the Email Address field of the Lead Object. In this case you could set the filterType to ownerEmail and set the emails of the leads as filterValues.
Then it is up to you how you gather the emails of those Leads who has a Custom Object attached. Luckily the REST API won’t throw an error if you provide a value that has no corresponding Custom Objects.
If your Custom Object is linked to a Lead, it's a bit complex but you can do like this:
Create a smart list and filter with "Has You Custom Object"
Get the smart list with API (GET /rest/asset/v1/smartLists.json)
Based on this list of Leads, get all Custom Objects (see the other answer).
Super simple.
When viewing the list of Custom Forms in Setup, I want to add a column that shows where those Custom Forms are in use (or null if used nowhere).
This is similar in principle to viewing the list of fields, which has a list of forms on which those fields are used.
What is the syntax I can use to add the appropriate column(s) to the view?
As far as I know, there is no linkage in the backend that connects categories (custom forms) to their host objects. This is probably because the list could be massive and the query would take quite a while to execute as it would have to traverse every object in Workfront or each form would store every parent object ID.
Unfortunately, you can't even search for objects by associated category IDs, so if you wanted to build this yourself you would need to query each object and search its categories to see if your custom form appeared.
I think this question is common, but I dont find a final solution.
Lets say I have a post type "event", what is the best approach to link a certain post to a certain person (speaker).
at the end i need a list of all speakers (alphabetical, according to their lastname) and of course the information of the speaker in a list of posts and single post view.
The speaker needs 4 data-fields: firstname, lastname, short-bio, weblink.
For a single event the amount of speker could be 1 ore many.
As far as I consider there a three different approaches to do this:
Custom fields
All needed custom fields are added directly to the cpt "events" using for example an acf repeater field.
the fields are blank textfields but a jquery ui script is providing an autocompleate feature with all values from the database (all firstnames, lastnames…)
Disadvantages from my perspektive: not so easy to query (especially when i have more than one speaker). The information about one certain speaker needed to give for every events.
Advantage: all information about a certain event, including the information about the speaker are editable on one page in the backend.
Posttype: "Speaker"
A second posttype named "speaker" will store all the infos about one speaker. An event could be related to one ore many speakers, for example by using the acf relationship field.
Disadvantages: all the information about the speaker are to be edit on another page in the backend. The user has first to create a speaker and second link this speaker to an event.
- question: is it possible, to include a second posttype into the backend of another posttype? For example by providing the possibility to create a new speaker inside the backend of the poststype "events"?
advantages: easy to query, easy to link a event to many speaker
Custom Taxonomy
I never tried this but maybe it is a good idea if possible.
The user can choose, add and edit a custom taxonomy providing all the informations (name, firstname, bio etc).
Is it possible to use more than one field for a custom taxonomy directly in the edit post view?
Maybe there is a final answer for this question?
I don't think their is a best approach, it depends on your need and your information architecture.
For example I may have a archive page of all speakers, so I can list all speakers and I can display the speaker's detail through the url http://mysite/speaker/ucheng. In this condition, I would prefer the post type solution.
Another Solution: Speaker User Role
What if you allow the speaker to edit their profile or upload some material for the event? If you want to do this, use default WordPress User and create a speaker role for it, so you can do some access control. Also, I can list the speakers on the frontend, and link the user to the event by using ACF.
For me, I would prefer the user role solution.
I'm grabbing a rss xml and using xpath parser etc to map the fields and create nodes. I've also used Feeds Tamper, Feeds Tamper php to take some feed items, perform logic and alter a fields content.
I'd like to know if there is a way to 'pre process' the feed items before nodes are created, perform logic on some source fields to work out i want to create a node from it?
See the Feeds API hooks, one of those in a custom module should let you alter the feed source beforehand - try hook_feeeds_after_parse to alter $result
I am currently trying to create a custom post type for recipes. My goal is to include the schema.org/Recipe and or hrecipe microformat and also have the ability to filter for ingredients in the future.
To do this I intend to have an interface with fields for title, photo, description, ingredients and instructions.
My question is: Should I create separate fields for each ingredient and each amount? Or would you say it is sufficient to just create one field for all ingredients? (also keeping the aforementioned microformats in mind).
http://schema.org/Recipe
http://microformats.org/wiki/hrecipe
Having ingredients as a single field is what is expected in both formats you linked to. Querying / filtering based on ingredient name will be slightly more complex...but you should be able to handle it.
There are 3 parts to this answer.
How should you save ingredients in WordPress
How should you allow users to modify the ingredients list
How should you display ingredients publicly
For point 1, you will have to give a bit of thought as to how you save the ingredient list and how you retrieve/display it along with how it is queried. One of the formats indicate you could have properties for each ingredient (still in draft).
You could save an ingredient list as a serialized PHP array, something like this:
$ingredients[]=array('milk','value'=>'125','type'=>'ml');
$ingredients[]=array('sugar','value'=>'1','type'=>'cup');
Since serialized PHP arrays are standardized, you could fairly easily write an WP query that takes it into account.
Keep in mind you will want to have a plan for when the 'value' and 'type' modifiers are set in stone and how to migrate what you saved if they are different.
For point 2, you could create a custom meta box that deserializes the PHP array saved and render individual controls for each ingredient along with controls to allow management (Add, Deletes, Updates).
For point 3....the easiest would be to get the value and manipulate it how you want in the output.