Challenge: Show and use WordPress-Page-Properties like User-ID, Page-ID etc.
Solution: Create a new JCI-Template with name “showpageproperties” and URL “dummyrequest” (or an URL with JSON) and this twig-Code:
{% set pageprop = wp_get_page_properties() %} get_current_user_id: {{pageprop.get_current_user_id}} get_post.ID: {{pageprop.get_post.ID}} all data: {{pageprop |json_encode | e}}
Then you can use this Shortcode to display the properties:
[jsoncontentimporterpro nameoftemplate="showpageproperties"]
In Action:
get_current_user_id: 0get_post.ID: 9540
all data:
{"get_permalink":"https://api.json-content-importer.com/pro-plugin-examples/pro-show-page-properties/","home_url":"https://api.json-content-importer.com","get_current_user_id":0,"userdata":false,"requestdata":{"HTTP_REFERER":"https://api.json-content-importer.com/pro-plugin-examples/pro-show-page-properties","REQUEST_URI":"/pro-plugin-examples/pro-show-page-properties/","QUERY_STRING":"","REMOTE_ADDR":"18.191.147.105","SERVER_PORT":"443","SERVER_ADDR":"85.13.135.188","SERVER_NAME":"api.json-content-importer.com","HTTP_HOST":"api.json-content-importer.com","HTTP_ACCEPT":"*/*","HTTP_USER_AGENT":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","argv":[],"argc":0},"get_post":{"ID":9540,"post_author":"1","post_date":"2022-01-30 20:37:32","post_date_gmt":"2022-01-30 19:37:32","post_content":"<!– wp:paragraph –>\n<p><strong>Challenge:</strong> Show and use Wordpress-Page-Properties like User-ID, Page-ID etc.</p>\n<!– /wp:paragraph –>\n\n<!– wp:separator {\"opacity\":\"css\"} –>\n<hr class=\"wp-block-separator has-css-opacity\"/>\n<!– /wp:separator –>\n\n<!– wp:paragraph –>\n<p><strong>Solution:</strong> Create a new JCI-Template with name \"showpageproperties\" and URL \"dummyrequest\" (or an URL with JSON) and this twig-Code:</p>\n<!– /wp:paragraph –>\n\n<!– wp:enlighter/codeblock –>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{% set pageprop = wp_get_page_properties() %}\nget_current_user_id: {{pageprop.get_current_user_id}}\nget_post.ID: {{pageprop.get_post.ID}}\nall data:\n{{pageprop |json_encode | e}}</pre>\n<!– /wp:enlighter/codeblock –>\n\n<!– wp:paragraph –>\n<p>Then you can use this Shortcode to display the properties:</p>\n<!– /wp:paragraph –>\n\n<!– wp:enlighter/codeblock –>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[[ nameoftemplate=\"showpageproperties\"]]</pre>\n<!– /wp:enlighter/codeblock –>\n\n<!– wp:separator {\"opacity\":\"css\"} –>\n<hr class=\"wp-block-separator has-css-opacity\"/>\n<!– /wp:separator –>\n\n<!– wp:paragraph –>\n<p><strong>In Action:</strong></p>\n<!– /wp:paragraph –>\n\n<!– wp:paragraph –>\n<p>[ nameoftemplate=\"showpageproperties\"]</p>\n<!– /wp:paragraph –>\n\n<!– wp:separator {\"opacity\":\"css\"} –>\n<hr class=\"wp-block-separator has-css-opacity\"/>\n<!– /wp:separator –>\n\n<!– wp:paragraph –>\n<p>Remark: In the field \"post_content\" the string \"\" is removed, as this could be cause trouble in executing there shortcodes again and again</p>\n<!– /wp:paragraph –>","post_title":"PRO: Show Page-Properties","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"pro-show-page-properties","to_ping":"","pinged":"","post_modified":"2023-08-12 18:57:46","post_modified_gmt":"2023-08-12 16:57:46","post_content_filtered":"","post_parent":9627,"guid":"http://api.json-content-importer.com/?page_id=9540","menu_order":120,"post_type":"page","post_mime_type":"","comment_count":"0","filter":"raw"},"cpf":{"_edit_lock":["1691859467:1"],"_edit_last":["1"],"jci_pagehead":[""],"_jci_pagehead":["field_602bcf9303a35"],"jci_pagetitle":[""],"_jci_pagetitle":["field_602bcf9d03a36"],"_wp_page_template":["default"],"keyaa":[""],"_keyaa":["field_6202eda62a2d0"],"keybb":[""],"_keybb":["field_6202edaa2a2d1"]},"categories":[{"term_id":38,"name":"Examples using the PRO JCI-Plugin","slug":"pro","term_group":0,"term_taxonomy_id":38,"taxonomy":"category","description":"Examples using the PRO JCI-Plugin","parent":0,"count":73,"filter":"raw","cat_ID":38,"category_count":73,"category_description":"Examples using the PRO JCI-Plugin","cat_name":"Examples using the PRO JCI-Plugin","category_nicename":"pro","category_parent":0},{"term_id":47,"name":"Programming of Wordpress with twig & JCI","slug":"wp-twig","term_group":0,"term_taxonomy_id":47,"taxonomy":"category","description":"Programming of Wordpress with twig & JCI","parent":0,"count":12,"filter":"raw","cat_ID":47,"category_count":12,"category_description":"Programming of Wordpress with twig & JCI","cat_name":"Programming of Wordpress with twig & JCI","category_nicename":"wp-twig","category_parent":0},{"term_id":46,"name":"twig-basic-syntax","slug":"twig-basic-syntax","term_group":0,"term_taxonomy_id":46,"taxonomy":"category","description":"Basic usage of twig with the JCI-Plugin","parent":0,"count":35,"filter":"raw","cat_ID":46,"category_count":35,"category_description":"Basic usage of twig with the JCI-Plugin","cat_name":"twig-basic-syntax","category_nicename":"twig-basic-syntax","category_parent":0},{"term_id":35,"name":"Using twig with the JCI-Plugin","slug":"twig","term_group":0,"term_taxonomy_id":35,"taxonomy":"category","description":"Using twig with the JCI-Plugin","parent":0,"count":63,"filter":"raw","cat_ID":35,"category_count":63,"category_description":"Using twig with the JCI-Plugin","cat_name":"Using twig with the JCI-Plugin","category_nicename":"twig","category_parent":0}]}
Remark: In the field “post_content” the string “jsoncontentimporterpro” is removed, as this could be cause trouble in executing there shortcodes again and again