內容簡介
使用這款外掛,您可以使用簡碼在前端顯示文章和使用者自定欄位資料,包括高級自定欄位(ACF)欄位。
您是否想要在前端顯示來自使用者資訊的資訊?
您是否想要在前端顯示文章自定欄位?
您是否使用 Advanced Custom Fields 創建了 Metabox,並希望顯示這些欄位?
使用此外掛,可在前端顯示任何文章或使用者資訊中的欄位。
基本範例
顯示目前使用者的電子郵件:[vg_display_data key="user_email" data_source="user_data"]
顯示目前使用者的名字:[vg_display_data key="first_name" data_source="user_meta"]
顯示目前使用者的全名:[vg_display_data key="first_name,last_name" data_source="user_meta"]
顯示目前文章的標題:[vg_display_data key="post_title" data_source="post_data"]
顯示目前文章的摘要:[vg_display_data key="post_excerpt" data_source="post_data"]
顯示文章 ID = 20 的分類:[vg_display_data object_id="20" key="category" data_source="post_terms" template="<b>Categories:</b> {{var}}" joiner=", "]
取得特色圖片網址:[vg_display_data key="_thumbnail_id" template="<b>Image url:</b> {{var}}" flag="file_url"]
取得特色圖片為 <img> 標籤:[vg_display_data key="_thumbnail_id" template="<b>Image:</b> {{var}}" flag="image_tag"]
進階範例
從包含參數 ?post_id=任何數字的 URL 顯示貼文 ID 的標題:[vg_display_data object_id_type="query_string" object_id="post_id" key="post_title" data_source="post_data"]
從 PHP 函式取得文章或使用者 ID:[vg_display_data object_id_type="callable" object_id="function_name" key="post_title" data_source="post_data"]
使用電話號碼 = 1234(meta_key=phone AND meta_value=1234)取得目前使用者的電子郵件:[vg_display_data object_id_type="find" object_id="phone:1234" key="user_email" data_source="user_data"]
參數
object_id = 文章 ID。如果留空,則使用目前的文章。可能的值:(留空)、current、數字、如果 object_id_type=query_string,則為查詢字串鍵;如果 object_id_type=callable,則為函式名稱;如果 object_id_type=find,則為 meta_key:meta_value
object_id_type = 如果 object_id 為空、current 或為數字,則留空。可能的值:query_string,callable,find
data_source = 用於查找資料的資料庫表。預設為 post_meta。可能的值:post_data、post_meta、user_data、user_meta、post_terms。
key = 欄位鍵值。可接受一個或多個以逗號分隔的鍵值。例如,要顯示全名=first_name,last_name。必填。
template = 用於顯示欄位的 HTML 片段。如果欄位為空,則不顯示 HTML。可選。
default = 如果欄位為空,使用的預設值。可選。
joiner = 如果欄位有多個值,則會使用此項目。可選。
外掛標籤
開發者團隊
② 後台搜尋「Display custom fields in the frontend – Post and User Profile Fields」→ 直接安裝(推薦)
原文外掛簡介
UPDATE
Our plugin now includes a settings page where you must whitelist every field that you want our shortcode to display in the front end, for security reasons. Your existing shortcodes will not work until you whitelist those field keys.
The “sanitization” parameter has been removed. All the output is sanitized with wp_kses_post always.
The “wp_filter” parameter has been removed. Now we have more specific parameters like wpautop=”yes” to turn line breaks into paragraphs, and do_shortcodes=”yes” to parse shortcodes.
Display post and user custom fields data anywhere on the frontend using a shortcode, including advanced custom fields (ACF) fields.
Do you want to display information from a user profile on the frontend?
Do you want to display custom fields from a post on the frontend?
Have you created metaboxes with Advanced Custom Fields and you want to display those fields?
Use this plugin to display any field for a post or user profile on the frontend.
Basic examples
Display email of the current user: [vg_display_data key="user_email" data_source="user_data"]
Display first name of the current user: [vg_display_data key="first_name" data_source="user_meta"]
Display full name of the current user: [vg_display_data key="first_name,last_name" data_source="user_meta"]
Display the title of the current post: [vg_display_data key="post_title" data_source="post_data"]
Display the excerpt of the current post: [vg_display_data key="post_excerpt" data_source="post_data"]
Display the categories of the post ID = 20: [vg_display_data object_id="20" key="category" data_source="post_terms" template="Categories: {{var}}" joiner=", "]
Get featured image url: [vg_display_data key="_thumbnail_id" template="Image url: {{var}}" flag="file_url"]
Get featured image as tag.: [vg_display_data key="_thumbnail_id" template="Image: {{var}}" flag="image_tag"]
Advanced examples
Display the title for the post ID from the URL containing the parameter ?post_id=ANY_NUMBER: [vg_display_data object_id_type="query_string" object_id="post_id" key="post_title" data_source="post_data"]
Get email of the current user with phone number = 1234 (meta_key=phone AND meta_value=1234): [vg_display_data object_id_type="find" object_id="phone:1234" key="user_email" data_source="user_data"]
Parameters
object_id = Post ID. Leave empty to use the current post. Possible values: (empty), current, number, query string key if object_id_type=query_string, meta_key:meta_value if object_id_type=find
object_id_type = Leave empty if object_id is empty, or current, or is a number. Possible values: query_string, find
data_source = What database table to use to find the data. Default = post_meta. Possible values: post_data, post_meta, user_data, user_meta, post_terms.
key = Field key. It accepts one or multiple keys separated by commas. For example, to display full name = first_name,last_name. Required.
template = HTML fragment to use to display the field, if the field is empty the html is not displayed. Optional.
default = Default value to use if the field is empty. Optional.
joiner = If the field has multiple values, it will join the values with this string. Default ” ” (one space). Optional.
flag = Use only if the field contains a file ID to conver the ID to URL or image tag. Default values: file_url , image_tag. Optional.
wpautop = Whether to turn line breaks into paragraphs. Optional, only for advanced users.
do_shortcodes = Whether to parse shortcodes before displaying the field value. Optional, only for advanced users.
