Print

PRO: Use Custom Post Fields

A WordPress-Page can have some Custom Post Fields (CPF). By that, one WP page can be almost identical to another; the only difference would be a CPF.

E.g., a CPF “language” on one page with “en” and on another “de”.
Having a JCI-Shortcode on such a page, the value of the CPF can be used in the API-URL and the twig-template.

With Twig, this works this way: Get the current pageID by wp_get_page_properties and then get the CPF by wp_get_custom_field_value:

{% set pageprop = wp_get_page_properties(debug, pageid) %}	
{% set pageid = jcipageparam.post.ID %}
pageid: {{pageid}}<br>
{% set valkeyaa = wp_get_custom_field_value(pageid, 'keyaa') %}
CPF-keyaa: {{valkeyaa | json_encode }}<br>
<hr>
{% set valueOfCPF = valkeyaa.0 %}
valueOfCPF: {{valueOfCPF}}<br>
{% if valueOfCPF matches "/test/" %}
yes, "test" is part of the CPF-Value
{% else %}
no, "test" is NOT part of the CPF-Value
{% endif %}

more on that an example: http://api.json-content-importer.com/build-api-url-with-use-custom-fields/

Was this article helpful?
3.2 out Of 5 Stars

3 ratings

5 Stars 0%
4 Stars 67%
3 Stars 0%
2 Stars 0%
1 Stars 33%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
On this page: