Using custom fields in WordPress | WordPress Plugins

WordPress is indeed a fantastic CMS, was not it highly flexible for developers and template developers. An advantage of this blogging platform, is that allows using custom fields, by the insertion of extra data, called meta-data, in combination with these custom fields, commonly known as custom fields.
It is because of these custom fields that sometimes there are templates for wordpress fantastic and everyone is open-mouthed asking how it was possible to do such a thing with WordPress. Well, these custom fields allow to recreate in WordPress almost everything, creating very different templates of what is common in the world of blogging.





If you have not noticed, the content editor of your WordPress blog, you must have under a field called “Custom Fields” or “Custom Fields”, which works very simply. On the left side is the “key” that you will call, and the right side of the “Value” which is the action that will unfold after calling the function. We will see below ….
Custom fields running through the ” Key ” ( key ) and “Value ” (value) . The only thing both have in common , is that you have to call both in the loop of your code .
    <? Php the_meta ( ); ? >
This is surely the simplest way to present the data. The template tag imports all the meta-data of the data and puts them in a CSS style sheet called post -meta . The ” key” is a parameter that is identified as post -meta -key .
Presenting a list of items with no order could be :
    <Ul class = ‘ post – goal ‘>
    <Li > <span class = ‘ post – meta- key’ > Personality: < / span > happy < / li >
    <Li > <span class = ‘ post – meta- key’ > Local Weather : < / span > fine < / li >
    < / Ul>
You may be interested in using this data in a more sophisticated way , and making use of unordered lists , to present their personality data and meteorology, for example.
To use the data call a higher form and more advanced , we use :
    get_post_meta ( $ post_id , $ key , $ single) ;
The parameters of this entry are as follows:
$ post_id
This is the article ID guarding the information contained in the meta-data .
Most times it is called by the function $ post-> ID .

$ key
The key is the key that contains the name of the value field goal .

$ single
This field can either be false as true ( true / false).
If true , it will result in calling a single result in the form of string.
If false or not specified, the function will return an array of custom field. This step is important if you use different keys $ with the same name .
Example of using a custom field
Imagine the situation where we have a key field with the title “Image” and where the value is the address of that same image .
To present the same image , we would use the following code :
    < ? Php $ image = get_post_meta ( $ post-> ID , ‘Image’ , true); ? >
    ? < Img src = ” <? Php echo $ image; ? > “Alt =” ” />
The possibilities are immense and after the use of special fields will depend on the needs of each and also your imagination. Experiment ! 🙂




LEAVE A REPLY

Please enter your comment!
Please enter your name here