• Hi,

    I know it might not be easy to do this but I’m still trying 🙂

    Retrieving a custom field is very easy thanks to your plugin.

    What I want to do is to use the result which is the value of that custom field as a parameter for another shortcode.

    For example let’s say the resulting value is date and time and I want to use that for a countdown plugin.

    [tminus t= "DD-MM-YYYY HH:MM:SS"]HTML to be displayed when the countdown reaches zero.[/tminus]

    is the normal code, when I try to replace the DD-MM-YYYY HH:MM:SS” with another shortcode which returns the value as date and time in that format, it does not get processed properly.

    This is not nested shortcode, where in that scenario, the shortcode is inserted between [shortcode] and [/shortcode], that is simple to do.

    Another possibility is to retrieve the result, put it somewhere and then access it with a value reference instead of shortcode, I’m not sure how to make something like that. AFAIK, there is no variable on a WordPress page and Javascript and PHP might not be able to do this as well.

    Any ideas?

    Kind regards,
    Tony

    https://wordpress.org/plugins/custom-content-shortcode/

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

    (@miyarakira)

    Yes, I believe it’s possible. Please take a look at the [pass] shortcode – right now its description is under Settings -> Custom Content -> Other.

    For example, you could do something like this:

    [pass field="field_name"]
      [tminus t="{FIELD}"] .. [/tminus]
    [/pass]
    Thread Starter yustein

    (@yustein)

    I will try this, I managed to do it with PHP but of course this will be better.

    The issue is the “field_name” parameter will be the result of another plugin like [plugin foo=”bar”][/plugin] so I hope it works.

    Thread Starter yustein

    (@yustein)

    It didn’t work, that t- plugin is a stubborn one, maybe it is because of that…

    Plugin Author Eliot Akira

    (@miyarakira)

    It does sound tricky – when you say “field_name” is the result of another plugin, do you mean the field name is dynamic and can change? Theoretically, it’s possible to use nested pass, using [pass]..[/pass] first, then [-pass]..[/-pass] inside. Maybe it’s possible to pass a field value as parameter to the second pass..not sure if that would work.

    You can confirm that the right field value is being passed:

    [field field_name]
    
    ..or..
    
    [pass field="field_name"]
      {FIELD}
    [/pass]
    Thread Starter yustein

    (@yustein)

    For example:

    I’m getting the date from the database, and trying to pass that as a parameter to another plugin. I think the syntax is OK, but I might be using the wrong variable name, also I’m trying to format the date as well.

    [raw][pass global="_GET" field="eventidpar"][loop type="pods_event" field="id_event" start="{FIELD}"][content field="date_event" date_format="d/m/Y"][field date_event][content field="title_event"][-pass datetime={DATE_EVENT} date_format="d/m/Y"][TS-VCSC-Countdown counter_scope="1" counter_interval="60" counter_date="{DATETIME}" reset_hours="0" reset_minutes="15" reset_seconds="0" reset_restart="true" date_zeros="false" date_days="true" date_hours="true" date_minutes="true" date_seconds="false" style="horizontal" border_thick="1" border_color="#dddddd" circle_width="5" color_background_basic="#f7f7f7" color_numbers_basic="#000000" color_text_basic="#000000" color_background_bars="#ffc728" color_numbers_bars="#ffffff" color_text_bars="#a76500" color_barback_bars="#a66600" color_barfore_bars="#ffffff" color_background_clock1="#000000" color_numbers_clock1="#ffffff" color_background_clock2="#000000" color_numbers_clock2="#00deff" color_dividers_clock2="#00deff" color_background_circles="#000000" color_numbers_circles="#ffffff" color_text_circles="#929292" color_circleback_all="#282828" color_circlefore_days="#117d8b" color_circlefore_hours="#117d8b" color_circlefore_minutes="#117d8b" color_circlefore_seconds="#117d8b" color_background_horizontal="#ffffff" color_flippers_horizontal="#ea9400" color_numbers_horizontal="#ffffff" color_text_horizontal="#929292" color_background_flipboard="#ffffff" column_equal_width="false" column_background_color="#f7f7f7" column_border_thick="1" column_border_color="#dddddd" margin_top="-50" margin_bottom="-50"]date passed: {DATETIME}[/-pass][/loop][/pass][/raw]

    Plugin Author Eliot Akira

    (@miyarakira)

    Woo, that is surely pushing the limit of what shortcodes can do. 🙂

    OK, let me see if I can understand what you’re doing there..

    [pass global="_GET" field="eventidpar"]
      [loop type="pods_event" field="id_event" start="{FIELD}"]
        [content field="date_event" date_format="d/m/Y"]
        [field date_event]
        [content field="title_event"]
        [-pass datetime={DATE_EVENT} date_format="d/m/Y"]
          [TS-VCSC-Countdown counter_date="{DATETIME}"...]
          date passed: {DATETIME}
        [/-pass]
      [/loop]
    [/pass]

    1) You’re passing $_GET[‘eventidpar’] to the loop’s start parameter. That will check if the beginning of the field value matches. Is there a reason for using start instead of value?

    2) I think the problem is how parameters are passed to [-pass]. This shortcode doesn’t have a date_format parameter. It should be something like this:

    [-pass field="date_event"]

    ..and passed to the next:

    counter_date="{FIELD}"

    In a way, I think you might achieve the whole thing simpler by using PHP.

    Thread Starter yustein

    (@yustein)

    1) just a mistake it should be value for sure instead of start
    2) I will try it that way

    3) there is a strong need for an inline language for WordPress. I can use PHP (which I do for this case) debugging PHP is a huge pain in my neck. I use the Global Content Blocks plugin to inject PHP and it works fine, I just don’t think that a WordPress developer should drop to PHP to accomplish such simple tasks as passing parameters and doing loops, checking logic etc.

    Did I miss something, is there an inline language plugin for WordPress?

    Thank you by the way for taking time to reply me 🙂

    Plugin Author Eliot Akira

    (@miyarakira)

    Yes, I understand what you mean – there are some plugins I’ve seen that can be used to place PHP script inside posts, but I think many users want a simpler solution. Have you had a chance to look at the [load] shortcode? It can used to include template files, which may have shortcodes as well as PHP.

    In a way, this plugin is becoming like a mini-language as you describe. It was not my original plan – at first I just needed to display one custom field, then some posts, and over time, the “vocabulary” grew. There are some limitations with the whole shortcode system: using brackets [] instead of a less common character; not able to nest shortcodes of the same name (that’s why there’s [loop], [-loop], [if], [-if]..); no simple way to avoid shortcode name conflict; etc. If I had a chance to design a language (!) from scratch, I would do it differently.

    So far, shortcodes are flexible enough and easy to learn. They’re like “macros” in a way, to simplify common tasks. I myself use this plugin in every project, because it makes it very fast to write templates.

    Anyway, please let me know how #2 goes. The question is, does the field date_event contain values with the right format to pass to TS-VCSC-Countdown.

    Thread Starter yustein

    (@yustein)

    You are correct!

    Using load is an option that I can try instead of using the plugin Global Content Blocks.

    Is there a standard for the files I can load?

    For example can shortcodes, PHP and HTML co exist in a single file, if yes how, if no what is the correct workflow to use PHP, html and shortcodes?

    And yes #2 did not work, exactly because of the format of the date…

    Another question is can you pass more than 1 parameter to a shortcode?

    Currently I’m using do shortcodes in php for complex parameter passing.

    It’s funny but I rather use do shortcode in PHP and use PHP just for logic and data manipulation. Remote debugging is not the easiest thing for PHP, what is your favorite method of debugging remote PHP?

    This has turned to be a very valuable information, I have to archive it 🙂

    Tony

    Plugin Author Eliot Akira

    (@miyarakira)

    With [load], you can do something like this:

    [load dir="views" file="template.html"]

    And inside wp-content/views/template.html:

    <h1>Example</h1>
    
    ..HTML with shortcodes..
    
    <ul class="post-list">
      [loop type="post" count="3"]
        <li class="post-list-item">[field title] - [field date]</li>
      [/loop]
    </ul>
    
    ..as well as PHP..
    
    <?php
      $some_value = complexFunction();
      echo do_shortcode('[code with="'.$some_value.'"]');
    ?>

    I hope that helps!

    For debugging, I set WP_DEBUG to true, and sometimes use Query Monitor.

    Plugin Author Eliot Akira

    (@miyarakira)

    Yes, you can pass more than one parameter:

    [pass fields="first_field, second_field"]
      [some_shortcode parameter="{FIRST_FIELD}" second="{SECOND_FIELD}"]
    [/pass]
    Thread Starter yustein

    (@yustein)

    I use Query Monitor as well with WP_DEBUG to true…

    The names of the fields passed are not important right, they can be anything like xyz1, xyz2?

    I think loading files and editing them locally over SSH is the best way for inserting PHP and shortcodes…

    Thanks a lot again, our conversation assured me that I’m on the right track and did not miss any information for my developments. 🙂

    Tony

    Plugin Author Eliot Akira

    (@miyarakira)

    Sure, I enjoy these programming talks, to learn how people are doing things.

    A more serious debug tool is Xdebug, although I haven’t used it much.

    When passing multiple fields, the names of fields correspond to the “tags”:

    [pass fields="xyz1, xyz2"]
      Passing {XYZ1} and {XYZ2}
    [/pass]

    It depends on preference and need, but I like to have all my templates organized in wp-content/views folder, so I can edit them with a code editor instead of inside WP admin.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Using a custom field as a parameter for another shorcode’ is closed to new replies.