• Resolved Jimmy Symmonds

    (@jimmy-symmonds)


    Hi Eliot
    We have created multiple custom post types using cpt-onomies. For the primary CPT we used the ACF Relationship field to link to the secondary CPT’s.

    So we have for example:

    Plant Profile (the primary CPT with ACF’s linking to secondary CPT’s
    – Plant Part Used
    – Plant Constituents
    – Animal Diseases

    On a Plant Profile posts I can use the basic Related shortcode to pull in the fields I want.

    [related field_name]
      [field title]
      [field thumbnail]
    [/related]

    But on the secondary CPT’s (with no ACF’s) can I list all the primary CPTs that were related to it?

    So on a Plant Part post titled ROOTS is there a shortcode to run through all the Plant Profile posts and list those that had roots selected?

    Hope that makes sense ??
    Thank you
    Jimmy

    https://www.ads-software.com/plugins/custom-content-shortcode/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Jimmy Symmonds

    (@jimmy-symmonds)

    The following lists all Plant Profiles, but I want only those related by Plant Part

    [loop type=plant_profile orderby=title]
    [field thumbnail-link]
    [field title-link]
    [/loop]
    Plugin Author Eliot Akira

    (@miyarakira)

    So on a Plant Part post titled ROOTS is there a shortcode to run through all the Plant Profile posts and list those that had roots selected?

    I think you can do it like this:

    Plant Profiles related to this Plant Part:
    
    [pass field=id]
    [loop type=plant_profile orderby=title]
      [if field=related_posts value={FIELD}]
        [field thumbnail-link]
        [field title-link]
      [/if]
    [/loop]
    [/pass]
    Thread Starter Jimmy Symmonds

    (@jimmy-symmonds)

    Thank you Eliot. The thinking behind these shortcodes really turns my mind to mush ??
    The above works with one change to if field=plant-parts rather than related_posts.

    [pass field=id]
    [loop type=plant_profile orderby=title]
    [if field=plant-parts value={FIELD}]
    [field thumbnail-link]
    [field title-link]
    [/if]
    [/loop]
    [/pass]
    Plugin Author Eliot Akira

    (@miyarakira)

    Oh, I just thought of a better way to do the same thing:

    [pass field=id]
    [loop type=plant_profile orderby=title field=plant-parts value={FIELD}]
    [field thumbnail-link]
    [field title-link]
    [/loop]
    [/pass]
    Thread Starter Jimmy Symmonds

    (@jimmy-symmonds)

    That is simpler, but doesn’t work. Not sure why. Just blank screen. Is the ‘if’ then still needed?

    Plugin Author Eliot Akira

    (@miyarakira)

    Ooh, yes, I see – in the above case, the [loop] will get only plant profiles when the field plant parts is exactly the current ID. This doesn’t work with relationship fields, which can have one or more IDs associated.

    OK, never mind. ?? Please use the working version using the [if] shortcode – this one is capable of filtering by relationship field.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘ACF and CPTs’ is closed to new replies.