Title: Escaping values in shortcodes
Last modified: May 13, 2021

---

# Escaping values in shortcodes

 *  Resolved [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/)
 * (@peterbraishfield)
 * [5 years ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/)
 * Excellent plug-in by the way.
 * I have been trying to create a list of future events using a shortcode along 
   the lines:
 *     ```
       [pissc orderby="meta_value" 
         mq_key_aa="date" 
         mq_value_aa ="now" mq_compare_aa =">" 
         mq_type_aa = "DATETIME"]
       ```
   
 * This works correctly if it is surrounded by
 *     ```
        ... 
       ```
   
 * , but it is poorly formatted.
    If not preformatted, it gives only posts with 
   the date=now, presumably because “>” is misinterpreted. How should the “>” be
   escaped so it works without preformatting?

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

 *  Thread Starter [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/)
 * (@peterbraishfield)
 * [5 years ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14435192)
 * Should have read:
    This works correctly if it is surrounded by
 *     ```
        ... 
       ```
   
 * , but is oorly formatted.
 *  Plugin Author [Aldo Latino](https://wordpress.org/support/users/aldolat/)
 * (@aldolat)
 * [5 years ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14436017)
 * Hello,
    first of all I am happy you’re finding this plugin useful for your needs!
 * On my test sites this shortcode is working fine:
 * `[pissc post_type=post number=-1 orderby=meta_value order=DESC post_status=publish
   ignore_sticky=1 mq_key_aa=date mq_value_aa=now mq_compare_aa=> mq_type_aa=DATETIME
   custom_field=1 meta=date custom_field_txt=Event_date: debug_query=1]`
 * Only make sure that the date stored in the custom field of the post has the same
   date format as in your WordPress preferences.
 *  Thread Starter [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/)
 * (@peterbraishfield)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14439762)
 * <p>Thanks for the quick reply.
    I have been experimenting using the classic editor
   on my test site. pissc shortcodes seem to work correctly provided they don’t 
   contain > or <.  When they contain the comparison ‘>’, they generally act as 
   if the comparison is  ‘=’ or unknown. However, if the shortcode is surrounded
   by
 *     ```
        and 
       ```
   
 * , it works.  Thus</p>
 * >  <p>
   >     ```
   >      [pissc orderby=meta_value mq_key_aa=date mq_value_aa =now mq_compare_aa ='>' mq_type_aa =DATETIME"] 
   >     ```
   > 
   > </p>
 * <p>works: it gives the right posts in the right order, but the result is, as 
   was specified, pre-formatted. If
 *     ```
        and 
       ```
   
 *  are omitted, it gives “no posts yet”.</p>
    <p>Your example also works within
 *     ```
        and 
       ```
   
 * , but only if &gt; is changed to ‘>’. If &gt; is left as it is, it behaves as
   if the ‘>’ is ‘=’.</p>
    <p>My assumption is that it is related to the fact that
   < and > have to be coded, but beyond that I remain mystified.</p>
 *  Thread Starter [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/)
 * (@peterbraishfield)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14439871)
 * Very sorry, I’m having terrible trouble with the formatting. I’ll try again later.
 *  Thread Starter [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/)
 * (@peterbraishfield)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14441542)
 * Let me have another go. There appears to be no way to preview one’s post, so 
   with the large amount of embedded html, fingers vey much crossed:
 * I have been experimenting using the classic editor on my test site. All pissc
   shortcodes appear to work, provided they don’t contain > or <. Also, the following:
 *     ```
       <pre> [pissc orderby=meta_value mq_key_aa=date mq_value_aa =2021-05-01 mq_compare_aa ='>' mq_type_aa =DATETIME"] </pre>
       ```
   
 * works. It gives the right posts in the right order, but it is, as specified, 
   pre-formatted. If
 *     ```
        and 
       ```
   
 *  are omitted, it gives “no posts yet”.
 * Your example also works similarly within
 *     ```
        and 
       ```
   
 * , but only if > is changed to ‘>’.  If > is left as it is, it behaves as if the
   > is ‘=’.
 * Again, without the
 *     ```
        and 
       ```
   
 *  it gives “no posts yet”.
 * My assumption is that it must be related to the fact that > and < have to be 
   coded. I’ve tried various browsers and the block editor with similar but not 
   identical results. I remain mystified.
 *  Thread Starter [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/)
 * (@peterbraishfield)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14441568)
 * Failed again.
 * Basically, the problem is that if the shortcode contains ‘>’, I cannot get it
   to work unless it is surrounded by a pre and /pre.
 *  Plugin Author [Aldo Latino](https://wordpress.org/support/users/aldolat/)
 * (@aldolat)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14441597)
 * I would to help you, but I am unable to understand the situation if the code 
   you write is stripped out by the forum engine. When you write the message in 
   the forum, make sure to use correctly the code tag. Surround the code between
   two backticks or use the button above the editor. Or use a pastebin service and
   write here the link to the code.
 *  Thread Starter [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/)
 * (@peterbraishfield)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14441845)
 * Will do.
 * For the moment, I’ve hacked your code in pis-functions-queries.php to allow GT,
   GE,LT,LE as comparison options with the obvious meanings, so that’s circumvented
   the problem for the moment and taken the urgency away. But it would be much better
   to get to the bottom of it.
 *  Thread Starter [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/)
 * (@peterbraishfield)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14442457)
 * Essentially, if the shortcode comparison contains > or < it fails to produce 
   the correct result (producing what = would). The only exception appears to be
   if the comparison is > and the code is enclosed in pre and /pre tags. Examples
   in the link.
 * For simplicity, there are 4 posts, dated using a meta ‘date’ field in April, 
   May, June and July. The comparison is with the date May 1st.
 * [Link to example](https://gist.github.com/peterquarendon/0057965f5863856623b173fdaabf9371)
    -  This reply was modified 4 years, 12 months ago by [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/).
 *  Plugin Author [Aldo Latino](https://wordpress.org/support/users/aldolat/)
 * (@aldolat)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14442797)
 * You can’t wrap a shortcode inside a pre tag. I gave you an example of a correct
   shortcode above.
 * Also make sure that there are no spaces before and after the equal character.
 * Finally, make sure that the date stored in the custom field is YYYY-MM-DD, i.
   e. for example 2021-05-15 (for 15th May 2021).
 *  Thread Starter [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/)
 * (@peterbraishfield)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14443781)
 * Thank you. It works now!
 * The problem was that I originally wrote (in html): mq_compare_aa=> as suggested
   by your example. This does not appear to work. I was originally reluctant to 
   write mq_compare_aa=> which looked as if it would confuse the parsing. So wrote
   mq_compare_aa=’>’. This does work if surrounded by pre and /pre tags, but not
   otherwise.
 * But writing mq_compare_aa=> works under both circumstances.
 * If you are interested,
    [here are the results of some experiments.](https://gist.github.com/peterquarendon/39382136d3340d8c1eab465ec7cb6119)
 * Thanks very much for your patience.
    -  This reply was modified 4 years, 12 months ago by [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/).
    -  This reply was modified 4 years, 12 months ago by [peterbraishfield](https://wordpress.org/support/users/peterbraishfield/).
 *  Plugin Author [Aldo Latino](https://wordpress.org/support/users/aldolat/)
 * (@aldolat)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14443831)
 * > Thanks very much for your patience.
 * You’re very welcome!

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

The topic ‘Escaping values in shortcodes’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-in-sidebar_aed6f1.svg)
 * [Posts in Sidebar](https://wordpress.org/plugins/posts-in-sidebar/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-in-sidebar/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-in-sidebar/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-in-sidebar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-in-sidebar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-in-sidebar/reviews/)

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 12 replies
 * 2 participants
 * Last reply from: [Aldo Latino](https://wordpress.org/support/users/aldolat/)
 * Last activity: [4 years, 12 months ago](https://wordpress.org/support/topic/escaping-values-in-shortcodes/#post-14443831)
 * Status: resolved