• Resolved Reflexa

    (@reflexa)


    Hello,

    I want to display several PODS-fields of the current post within the post_content-field. That’s easy with Pods-code, this works:
    [pods field="my_custom_field"] or [pods]{@my_custom_field}[/pods]

    But I want this to do by using a template.

    I tried many things, but they didn’t work. I think I have to do with a where-Code: The ID has to be the ID of the current post. But the magic tag inside the [pods]-brackets doesn’t work:

    [pods name="my_pod" template="my_template" where="id={@id}"]

    How can I solve this problem?

    Thanks for you help.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hello @reflexa

    But I want this to do by using a template.

    What kind of template?
    Theme (WordPress) template or Pods template?

    Thanks, Jory

    Thread Starter Reflexa

    (@reflexa)

    Hello Jory,
    Pods template.
    Thanks,
    Reflexa

    Plugin Author Jory Hogeveen

    (@keraweb)

    Thread Starter Reflexa

    (@reflexa)

    Hello Jory,
    I think you don’t understand my problem.

    I’ve got got an PODS-Template with [each]HTML {magic-tags} HTML[/each]

    I could use the code of PODS-Template without a pods-template inside the post-content-field.
    But I want a shorter code – and I think it’s much more easier if I change one pods-template instead of the [pods-code] in many posts.

    The problem is now: A pods-template shows many results, but I want only to show the fields of the current post and not from other posts.

    Best regards, Reflexa

    Plugin Author Jory Hogeveen

    (@keraweb)

    Ah check.
    Your where statement is incorrect in that case.
    where="id={@id}" would match the ID of the current post, not it’s relationship field.

    You will have to create your own function with output a correct where syntax to search for. The field would not be {@id} but {@custom_field}.
    To call a custom function use: {@custom_field,my_function}, see: https://docs.pods.io/displaying-pods/magic-tags/display-filters-with-magic-tags/

    Also your where syntax will need to use IN instead of =. Example: where="t.id IN (1,2,3,4)"

    Also, see this page:
    https://docs.pods.io/displaying-pods/pods-templates/using-shortcodes-in-pods-templates/#masthead

    Good luck!
    Cheers, Jory

    Thread Starter Reflexa

    (@reflexa)

    Sorry for my bad English. That’s why it’s not so easy to understand my issues.

    Now I added define('PODS_SHORTCODE_ALLOW_SUB_SHORTCODES',true); to my wp-config.php.

    Basically I want match the ID of the current post to show the fields of the custom-fields of the current post.

    Example:
    Pod: members
    custom-fields: phone (field-type: Phone), downloads (field-type: File / Image / Video)

    Entries:
    id=1, post_title: Tarzan, post_content: King of the jungle, phone: 999-111, downloads: tarzan.pdf
    id=2, post_title: Simba, post_content: Lion King, phone: 999-222, downloads: simba1.pdf, simba2.pdf
    id=3, post_title: Arielle, post_content: The little mermaid, phone: 999-333, downloads: arielle.pdf

    To display also the custom fields without modifying the wordpress-theme, I add this code into post_content of Tarzan:

    [pods name="members" template="my_template"]

    template: my_template:

    <ul>
    	<li>Phone: {@phone}</li>
    	<li>Downloads: {@downloads}</li>
    </ul>

    Now I look at domain.com/members/Tarzan:

    The result is:

    Tarzan
    King of the jungle

    Phone: 999-111
    Downloads: https://domain.com/wp-content/uploads/2019/12/tarzan.pdf

    Phone: 999-222
    Downloads: https://domain.com/wp-content/uploads/2019/12/simba1.pdf https://domain.com/wp-content/uploads/2019/12/simba2.pdf

    Phone: 999-333
    Downloads: https://domain.com/wp-content/uploads/2019/12/arielle.pdf

    Unfortunately not the result I want. I want:

    Tarzan
    King of the jungle

    Phone: 999-111
    Downloads: https://domain.com/wp-content/uploads/2019/12/tarzan.pdf

    So I tried the following pods-code:

    [pods name="members" template="my_template" where="id={@id}"]
    and
    [pods name="members" template="my_template" slug="{@id}"]

    The result is:

    Tarzan
    King of the jungle

    Okay, the code doesn’t work.

    That’s why I added define('PODS_SHORTCODE_ALLOW_SUB_SHORTCODES',true); to my wp-config.php.

    Now I wrote:
    [pods name="members" template="my_template" where="id={@id}" shortcodes=1]
    and
    [pods name="members" template="my_template" slug="{@id}" shortcodes=1]

    The result is:

    Tarzan
    King of the jungle

    Okay, obviously {@id} inside the [pods …] doesn’t work.

    Now I am at a loss.

    Thanks for your help.

    Best regards, Reflexa

    Plugin Author Jory Hogeveen

    (@keraweb)

    [pods name=”members” template=”my_template” where=”id={@id}” shortcodes=1]
    and
    [pods name=”members” template=”my_template” slug=”{@id}” shortcodes=1]

    You can also do:

    [pods name="members" template="my_template" id="{@id}"]

    Besides that.
    If you are in a Pods template you dont need shortcodes.
    You can just use the magic tags that you’ve used in my_template.

    So instead of the shortcode you can just use this:

    <ul>
    	<li>Phone: {@phone}</li>
    	<li>Downloads: {@downloads}</li>
    </ul>

    Keep in mind, this is ONLY for Pods Templates.
    If you use this in the regular Post Content then it should be this:

    <ul>
    	<li>Phone: [pods field="phone"]</li>
    	<li>Downloads: [pods field="downloads"]</li>
    </ul>

    Let me know if this helps!

    Cheers, Jory

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Insert Pods-Custom-Fields to current post_content with Templates’ is closed to new replies.