• Resolved Gantry_Steve

    (@gantry_steve)


    Absolutely love this plugin. I use it to pass post titles to my frontpage. How could I use this plugin to pass post titles and urls based on the value of a custom post content?

    For example: I create a custom post content field called “homepage_headline_location” and then I set the value in a post something like “homepage_headline_location=1”.

    It would be great if I could then use this shortcode to pull that specific post’s title, something like

    <h3>
    [loop type="post" field="homepage_headline_location"]
    <a href="[content field_value="1" field="url" format="false]">[content field_value="1" field="title"]</a>

    So this basically pulls the field value and then makes that value the post ID. That way I keep track of those values in posts instead of having to code specific ids into widgets on my frontpage.

    Thanks!

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hello, I’m glad you’re finding the plugin useful.

    If I understand the question correctly, you want to create a field then use its value as the post ID to get title, url, etc. It should be possible with the [pass] shortcode, like this:

    [pass field="homepage_headline_location"]
        <a href="[content id="{FIELD}" field="url" format="false]">[content id="{FIELD}" field="title"]</a>
    [/pass]

    Please let me know if it works for you. Also, here is the description of the [pass] shortcode: Field as parameter

    (I see that you put format="false" for the URL – for the next plugin update, I’ll change it so you don’t have to do that, because URL should be unformatted by default.)

    Plugin Author Eliot Akira

    (@miyarakira)

    Please see the update to version 0.3.3, the post URL should be displayed without formatting by default.

    As for your original question, I see that you’re using the loop to get all post titles and URLs. I haven’t fully tested the [pass] shortcode inside a loop, so I’m not sure if this will work:

    [loop type="post"]
        [pass field="homepage_headline_location"]
            <a href="[content id='{FIELD}' field='url']">[content id="{FIELD}" field="title"]</a>
        [/pass]
    [/loop]

    Theoretically, this would go through all posts, and for each post, get the value in the custom field homepage_headline_location and display links using that value as post ID. It seems like there must be an easier way..

    Plugin Author Eliot Akira

    (@miyarakira)

    Hmm, reading your question again, I wonder maybe I misunderstood.

    Do you mean that you would like to display links to posts that have a specific custom field value? If so, this is a feature I’ve been thinking about implementing in the loop shortcode, to be able to query posts by custom field. For example:

    [loop type="post" field="homepage_headline_location" value="1"]
      <a href="[content field='url']">[content field="title"]</a>
    [/loop]

    This would display links to all posts with the custom field value 1. Let me know if this is what you mean, I’ll include it in the next update.

    fabryven

    (@fabryven)

    hi Eliot,
    thank you for your great plugin!

    but I ask you not yet activated the possibility of the loop in custom field?
    for example I tried to insert:
    [loop type=”hotels” field=”star-hotel” value=”4 star”]
    and does not work….

    only the [loop type = “hotels”], it works perfectly!

    and I ask you but you can make a loop of two or more custom field?

    for example:
    [loop type=”hotels” field=”star-hotel” value=”4 stars” field=”service-hotel” value=”all inclusive”]

    Plugin Author Eliot Akira

    (@miyarakira)

    Hello, thank you for the comment. For the latest update, I added a set of parameters to query for custom field values.

    Single field:

    [loop type="hotels" field="star-hotel" value="4 star"]

    Single field compare:

    [loop type="hotels" field="star-hotel" compare="NOT EQUAL" value="3 star"]

    Two field values:

    [loop type="hotels" field="star-hotel" value="4 stars" field_2="service-hotel" value_2="all inclusive"]

    Two field values relation:

    [loop type="hotels" field="star-hotel" value="4 stars" relation="OR" field_2="service-hotel" value_2="all inclusive"]

    Please let me know how it works for you.

    fabryven

    (@fabryven)

    fantastic Eliot! all works…

    I tried all 4 cases: single field, single field appears, Two field values??, field values ??Two relations and no problem! is perfect

    could be useful for the development of the plugin use these variables also for taxonomies and/or filter 1 tax with 1 or 2 field. ??

    anyway thanks and congratulations for your plugin!

    Finally, I ask you: can I filter the loop with RANDOM order?

    Plugin Author Eliot Akira

    (@miyarakira)

    I’m glad to hear that the new parameters are working well.

    Yes, I agree there’s more potential for supporting tax/field/other meta queries. I’m thinking how I far I should go with them, and still keep it simple – there are many combinations.

    Random order is a good idea, it could be useful for posts, images, etc. I haven’t tried yet, but orderby=”rand” might work.

    Thanks for the feature suggestions, and testing the new parameters to make sure they’re working correctly. I think I will start a new support topic about what more functions people need, and maybe removing some features that are not used, to keep the plugin compact. If you have any more ideas or opinions, let’s continue on the new topic.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Fetch from custom post content field?’ is closed to new replies.