Title: Short code view based on field value
Last modified: August 30, 2016

---

# Short code view based on field value

 *  Resolved [nkholski](https://wordpress.org/support/users/nkholski/)
 * (@nkholski)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/short-code-view-based-on-field-value/)
 * I don’t know if I missed something obvious but I can’t this to work:
 * I have a custom content type (person) that I want to display as selected post
   from on different pages (as contact person(s) for that page).
 * I try to find something like this to display only the post with Anna set as title:
   [
   query slug=”contacts” args=”post_title=’Anna'”]
 * Or this for two persons:
    [query slug=”contacts” args=”post_title=’Anna’,’Dana'”]
 * How can I achieve something like this? Whatever I try it will list all posts 
   of the person content type.
 * [https://wordpress.org/plugins/query-wrangler/](https://wordpress.org/plugins/query-wrangler/)

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

 *  Plugin Author [Jonathan Daggerhart](https://wordpress.org/support/users/daggerhart/)
 * (@daggerhart)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/short-code-view-based-on-field-value/#post-6622730)
 * Hi nkholski,
 * Sorry for any confusion. Shortcode args are not extremely well documented.
 * For reference, here is how query short code args work:
 * First, there is one big rule that cannot be avoided in the current version of
   Query Wrangler, and that is:
 * **The `args=` property can only the same accept parameters as the `WP_Query( '
   args' )` class accepts as a string.**
 * [https://codex.wordpress.org/Class_Reference/WP_Query](https://codex.wordpress.org/Class_Reference/WP_Query)
 * That means all complex queries that require arrays are out.
 * The second rule is that it can only accept parameters available to the WP_Query
   class.
 * In your case, there is no query parameter for the `post_title`, so you’ll need
   to use something else.
 * For getting a single page or post, I recommend the `name` (post slug) or `pagename`(
   page slug) parameters.
 * `[query slug="test-args" args="name=zerimar"]` will get a post with the slug 
   of “zerimar”.
 * In your first case, that could look like this:
 * `[query slug="contacts" args="name=anna"]`
 * Unfortunately for your second case, the name and pagename parameters do not accept
   multiple values, so you need to probably use a shared post_tag,
 * `[query slug="contacts" args="tag=friends"]`
 * or category.
 * `[query slug="contacts" args="category_name=friends"]`
 * For queries on multiple targets, figure out how they relate to each other (taxonomy
   term, meta value, etc ), create that relationship, and then use that relationship
   in your query arguments.
 * **Meta Value Example:**
 * 1. Assume both Anna and Dana have a meta field with the key of “is_smart” and
   the value of “yes”:
 * `[query slug="contacts" args="meta_key=is_smart&meta_value=yes"]`
 * 2. Assume you want to show only contacts that have a Featured Image, and you 
   want to sort them by their post_titles.
 * `[query slug="contacts" args="meta_key=_thumbnail_id&orderby=title"]`
 * **Contextual tokens examples:**
 * Assume I want to create a “related posts” query that will show a list of posts
   related to the current one being viewed. For this to happen, I need to get the
   context of the current post, and its post_title. Then, I’m going to pass that
   value into the query as a search parameter.
 * `[query slug="related-posts" args="s={{post:post_title}}"]`
 * Let’s walk through it.
 * 1. I created a query in Query Wrangler called “Related Posts”
    2. I created a
   post titled “Tom Hanks” and placed the above shortcode into the new post. 3. 
   When viewing the page, the shortcode with convert `{{post:post_title}}` into 
   the value of the post_title property of the current post `$post->post_title`.
   4. Using the WP_Query search parameter “s”, the query will return posts that 
   mention “Tom Hanks”.
 * This example is a bit contrived, but hopefully it provides some insight.
 * One more contextual token example:
 * Assume you have a pages in a hierarchy and you want for parent pages to always
   show a list of their children pages.
 * `[query slug="child-pages" args="post_parent={{post:ID}}"]`
 * For contextual queries that appear on many pages, you may consider placing a 
   Query Wrangler Widget in a sidebar. They can also accept these argument strings.
 * Hope this helps,
    Jonathan
 *  Thread Starter [nkholski](https://wordpress.org/support/users/nkholski/)
 * (@nkholski)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/short-code-view-based-on-field-value/#post-6622795)
 * Hi!
 * Other stuff came up and I didn’t see your reply. Thank you for your effort, I’m
   sure that this is more than enough for me to continue the work.
 * all the best!

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

The topic ‘Short code view based on field value’ is closed to new replies.

 * ![](https://ps.w.org/query-wrangler/assets/icon-256x256.jpg?rev=3279076)
 * [Query Wrangler](https://wordpress.org/plugins/query-wrangler/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/query-wrangler/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/query-wrangler/)
 * [Active Topics](https://wordpress.org/support/plugin/query-wrangler/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/query-wrangler/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/query-wrangler/reviews/)

## Tags

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

 * 2 replies
 * 2 participants
 * Last reply from: [nkholski](https://wordpress.org/support/users/nkholski/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/short-code-view-based-on-field-value/#post-6622795)
 * Status: resolved