Wordpress: I want to get the name of a meta field - php

I am using the Post Type Builder for Wordpress to create Custom Post Types.
I would like to get the name of a meta field in the front-end. I am able to get the values, but I would like the names. How could I do this?
For example, I have made a custom post type for a machine selling website.
The user is able to add a new machine (post type), add the building year, dimensions, weight and so (meta data).
I would like to display: Year: 2001. How can I get "Year"?
Thank you in advance!

The best way would be to use the Post Type Builder template editor (https://themify.me/docs/post-type-builder-plugin-documentation#templates).
If not that, then the simple answer is that you already know what the name of the field is since you're passing the key in. You can just hard-code that into your page template.
The final method would be to unserialze and parse out the ptb_plugin_options item from the wp_options table. This is one big blob that holds all of the config info for the plugin. You would retrieve it something like:
$ptb_plugin_options = unserialize(get_option('ptb_plugin_options'));
echo $ptb_plugin_options['cpt']['POSTTYPE']['meta_boxes']['text_1']['name'];
Replacing POSTTYPE with the actual posttype you're using and text_1 with the meta_key of the box in Post Type Builder.

Related

Pushing custom field data to an array within a plugin

Good Morning
I not very proficient in PHP, on a plugin I am using for car listings there is 'car data' which is filled in while adding a car, I want to add a new option and entry field. I have used a separate plugin to add a custom field to the vehicle listing post type, the problem is outputting the value to the post page.
Within the car listing plugin I found the below php file
https://github.com/barrykooij/wp-car-manager/blob/master/src/Vehicle/Data.php
I added another entry to the array directly and it displayed in the place I want, the questions I have are;
Can I write a function in functions.php to append something to this array?
How would I specify for the values used to be that of my custom field?
Maybe I am barking completely up the wrong tree here but some advice would be appreciated.
Thanks

is it possible to show wordpress ACF fields in popup and save them manually

In my WordPress project admin, I created post object of custom post 'People' in custom post 'Project'.
Now when adding project if required people isn't available user should be able to add people. For this I am thinking of adding 'Add People' link which on click will show the custom fields of post 'People' in popup. On saving data, it will be selected in post object.
Is this possible? If yes how am I approach this?
I googled but not getting any idea about how to approach this?
What will be the best solution for this case?
Any suggestions are welcome.
Sounds like you've got a custom post type of "Project" and then you're trying to find a good way of adding people to that project.
I'm not sure if you have a custom post type of "Person" but it sounds like you might, if that's the case then the easiest approach would be to have whoever is entering data to just go and add the new person from the custom post type of person. Then have a relationship field in project linked to person.
If Person isn't a custom post type and it's just a field (so all that you need to know is the person's name) then it might be simpler to use a custom taxonomy where a new term can be added directly from the meta box. see this doc page for more info on that.

WordPress - Assign Meta Data to Custom Post Type

I have a website which uses a custom post type of Treatments, which we're using the CPT-onomies plugin to link as a taxonomy to other custom post types.
We have another post type, Practitioners, which I need to link related treatments too, this part is easy. But we also need to enable them to save prices per treatment and have a POA (price on application) option too.
At the momement this is rather awkwardly coded with serialised arrays, which makes long work of manipulating and reporting on the data.
What's the easiest approach to adding these two extra fields to the custom post type?
Have a look at Pods (http://pods.io/). This plugin enables an interface to define custom post types with a lot of options.
Including relationships, so you can add records of POA, and then assign these to the pod Practitioners for instance.
I ended up resolving this by using ACF Pro, specifically repeater fields within a field group on the Practitioner page that allow them to select multiple Treatments and assign pricing to each one.

Get ACF from relationship field with Timber

I'm using Advanced Custom Fields on a custom post type. On the homepage I have a relationship field to select one of the posts in the custom post type.
Using Timber, I'm struggling to get the ACF fields for that relationship post into the Context. I can get the standard wordpress info like title and content, but not the ACFs.
I think I need to use TimberPost, but haven't had any success so far.
This is in my page template. In the view it just outputs all the standard WP stuff:
$context['featureRelationship'] = get_field('feature');
So I tried this, but I'm going wrong somewhere:
$context['featureRelationship'] = new TimberPost(get_field('feature'));
Appreciate any help, thanks
Sorted, so the php was right:
$context['featureRelationship'] = new TimberPost(get_field('feature'));
But I should have used a post object acf field instead of relationship

Wordpress Custom Table or Custom Post Types?

I am using wordpress to make a site which has job posts, and I want to know the best way to go about storing company details, as each job post must be linked to a company.
Normally I would have just set up a companies table in my database, and put a company ID within each job post, then joined to get company details.
However I have often come across the idea that it's not always the best option in Wordpress development to create new tables (such as here). Instead I would be better using custom post types.
But how would this work to store company details? Would it be right to create a custom post type for companies, and then add a new post for each company? And then use custom fields to store data about each?
Or would I be best off creating new database tables? What is better and why?
I suppose it is the best to use custom post types with post meta in conjuction with meta boxes. This way, you will be able to manage in ease your companies, and yet, you will be able to operate custom queries on companies via the WP_Query class.
Currently I am building a business directory for a my client, so I decide to use the custom post types because of flexibility. Also I made a custom script for managing company information in conjuction with post meta.
Take a look in the screen shot to undestraint what I mean :
Note that whenever I like to add new data to companies, I am free to just add some extra meta boxes, and then save the extra data as meta data for the post. This way is matter of minutes to extend a standart data entity.
What you need:
http://codex.wordpress.org/Post_Types
http://codex.wordpress.org/Function_Reference/add_meta_box
http://codex.wordpress.org/Function_Reference/register_taxonomy (optionaly)
http://codex.wordpress.org/Function_Reference/get_post_meta
http://codex.wordpress.org/Function_Reference/add_post_meta
I hope you this will help you :)
Create an Custom post type
add the custom fields to that custom post type for different fields you need,
There is no need of creating table manually,
http://wordpress.org/plugins/custom-post-type-ui/
http://wordpress.org/plugins/advanced-custom-fields/
and you can apply the sorting on some custom field you added to the post type,

Categories