Title: Shortcode parameters not working
Last modified: August 30, 2016

---

# Shortcode parameters not working

 *  Resolved [codypersinger](https://wordpress.org/support/users/codypersinger/)
 * (@codypersinger)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/)
 * I have a page template “show-template.php”. This template will be applied across
   several pages. Each page the template is applied to will correspond to a season
   of a television show, i.e. “Season 1”, “Season 2”, etc.
 * I’m using the Advanced Custom Fields plugin to add custom fields to both posts
   and pages. The custom field name is “Season Number” and is referenced with the
   name “season_number”.
 * The “Season Number” field for the “Season 1” page is set to equal “1”. I have
   some posts, “Season 1 Episode #”, whose “Season Number” field is also set to 
   equal “1”.
 * Using a single page template (“show-template.php”) I want ALM to pull in the 
   corresponding posts. So, on the “Season 1” page, ALM will pull in all the Episodes
   which correspond to Season 1, but none of the episodes from other Seasons. On
   the Season 2 page, ALM will pull in all the Episodes from Season 2, but not from
   other seasons. Etc.
 * My repeater template is able to detect the “Season Number” value for each post,
   but I am not able to detect the “Season Number” value for the _page itself_.
 * In my “show-template.php” I have:
 * `<?php $page_season_number = get_field('season_number'); ?>`
 * Now what I want to do is pass this $page_season_number variable into the shortcode
   as the meta_value. I have tried:
 * `<?php echo do_shortcode('[ajax_load_more posts_per_page="1" button_label="View
   More" destroy_after="2" scroll="false" meta_key="season_number" meta_value="'.
   $page_season_number . '"]'); ?>`
 * However, the shortcode does not seem to work with meta_key and meta_value. I 
   have tried hard-coding the meta_key to equal “season_number” and the meta_value
   to equal “2”, but ALM simply pulls in all posts regardless. I can’t seem to make
   the meta_value and meta_key work via shortcode.
 * I am able to pass the meta_value and meta_key into the get_post() method inside
   the repeater template. However, I have not successfully found a way to pass the
   $page_season_number value into the repeater template. I hope I have explained
   this clearly. I would be happy to clarify any point. Thank you for any help you
   can provide.
 * [https://wordpress.org/plugins/ajax-load-more/](https://wordpress.org/plugins/ajax-load-more/)

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

 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736614)
 * Hi.
    Is there anyway you can test a standard WP_Query / Meta_Query to see if 
   you can get the results using the values of the season?
 * Do you know what I mean?
 *  Thread Starter [codypersinger](https://wordpress.org/support/users/codypersinger/)
 * (@codypersinger)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736619)
 * Hi dcooney, thanks for your speedy reply. I am somewhat familiar with the meta_query–
   or at least know where to find the documentation on it. How are you suggesting
   I use it? My apologies for not understanding fully – I have been working on this
   issue for many hours today and my brain is starting to get a little fried!
 * I’d be more than happy to try whatever you recommend. Thanks very much for your
   effort in troubleshooting, and for the excellent plugin.
 *  Thread Starter [codypersinger](https://wordpress.org/support/users/codypersinger/)
 * (@codypersinger)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736620)
 * I would like to add that during my testing of the ALM shortcode, I was not able
   to select by _post\_type_ either. I am able to get _post\_type_ to work when 
   I pass it into the repeater template:
 * `get_posts('post_type=post')`
 * Other ALM shortcode works fine, such as _destroy\_after_, _scroll_, and _button\
   _label_ – but _post\_type_, _meta\_key_, and _meta\_value _do not seem to work
   in my shortcode.
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736622)
 * Hey, no problem.
 * I’m curious is the issue is actually related to the shortcode at all.
    So I’m
   suggesting you put together a standard WordPress query using the parameters you
   are passing to the shortcode to ensure it actually works.
 * For example.
 *     ```
       $wp_query = new WP_Query (array (
          'post_type' => 'post',
          'post_per_page' => -1,
          'meta_query' => array(
              array(
                  'key' => 'season_number',
                  'value' => $page_season_number,
                  'compare' => 'IN'
              )
          )
       ));
       ```
   
 *  Thread Starter [codypersinger](https://wordpress.org/support/users/codypersinger/)
 * (@codypersinger)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736625)
 * Excellent, thanks for your clarification. I will report back as quickly as possible.
 *  Thread Starter [codypersinger](https://wordpress.org/support/users/codypersinger/)
 * (@codypersinger)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736704)
 * Sorry for the late reply, I did not have access to my dev environment last night.
   I set up the WP_Query on the “show-template.php” page. I used the following:
 *     ```
       <?php $wp_query = new WP_Query (array (
             'post_type' => 'mag_show_post',
             'post_per_page' => -1,
             'meta_query' => array(
                  array(
                      'key' => 'season_number',
                      'value' => $page_season_number,
                      'compare' => '='
                 )
            )
       )); ?>
       ```
   
 * The query returned the expected posts which match the season_number, so it seems
   to work well.
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736705)
 * Ok thanks.
    Is it possible to share a link to the page with the shortcode active?
 *  Thread Starter [codypersinger](https://wordpress.org/support/users/codypersinger/)
 * (@codypersinger)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736706)
 * Unfortunately the page currently exists only in my local environment, and I believe
   client confidentiality may prohibit me from sharing even if it were not. I do
   realize this may make it very difficult or impossible to debug and apologize 
   for the inconvenience. I would be happy to share any further details or code 
   required.
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736707)
 * Yea without a link I cant really debug.
    But it sounds like an issue with the
   post type.
 * Did you say you are unable to pass the post type?
 *  Thread Starter [codypersinger](https://wordpress.org/support/users/codypersinger/)
 * (@codypersinger)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736708)
 * I am unable to pass the _post\_type_ via the shortcode, but if I pass it into
   the get_posts() method in the repeater template it does work. The same is true
   for _meta\_key_ and _meta\_value_.
 * This is the code I am using in the repeater template:
 *     ```
       <span>
       <?php global $post;
       $recentposts = get_posts(array(
       	'post_type' => 'mag_show_post',
       	'meta_key' => 'season_number'
       ));
       foreach ($recentposts as $post) : setup_postdata($post);
       $post_season_number = get_field('season_number'); ?>
           //display each post here
       <?php endforeach; wp_reset_postdata(); unset($post); ?>
       </span>
       ```
   
 * I’m not doing anything with $post_season_number in the repeater template because
   I wasn’t able to provide it access to the $page_season_number. This wouldn’t 
   be a problem if I could pass $page_season_number through the shortcode, but unfortunately
   that’s been an issue as well. Somehow I need to provide both the $page_season_number
   and the $post_season_number in the same context so that I can compare the two.
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736709)
 * I dont understand why you can’t access the post type in the shortcode.
 * What happens?
 *  Thread Starter [codypersinger](https://wordpress.org/support/users/codypersinger/)
 * (@codypersinger)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736710)
 * First I’ll note that I’m using the shortcode like so, not sure if it makes a 
   difference:
 * `<?php echo do_shortcode('[ajax_load_more posts_per_page="1" button_label="View
   More" destroy_after="2" scroll="false"]'); ?>`
 * All of the parameters you see there work perfectly. However, if I try this:
 * `<?php echo do_shortcode('[ajax_load_more posts_per_page="1" button_label="View
   More" destroy_after="2" scroll="false" post_type="mag_show_post"]'); ?>`
 * or this:
 * `<?php echo do_shortcode('[ajax_load_more posts_per_page="1" button_label="View
   More" destroy_after="2" scroll="false" meta_key="season_number" meta_value="2"]');?
   >`
 * Using either of those shortcodes, ALM will display only posts with the post_type
   of ‘post’. It will not display posts with the specified post_type or the specified
   meta_key.
 *  Thread Starter [codypersinger](https://wordpress.org/support/users/codypersinger/)
 * (@codypersinger)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736711)
 * !!!! I believe I’ve just solved my own problem, and I feel like a complete idiot!
 * I removed the get_posts method from my repeater template and the shortcode seems
   to be working beautifully now. I think I completely misunderstood how ALM works
   in regards to the repeater template. ALM is making its own calls to grab posts,
   I just need to provide it the specifics. Instead, I was trying to write the call
   to grab posts. Thanks so much for your assistance in this dcooney, I doubt I 
   would have ever figured it out if I hadn’t been tinkering during this debug session.
   You rock!
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736712)
 * yea, alm creates the query for you.
 * Best of luck!

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

The topic ‘Shortcode parameters not working’ is closed to new replies.

 * ![](https://ps.w.org/ajax-load-more/assets/icon-256x256.png?rev=2944639)
 * [Ajax Load More – Infinite Scroll, Load More, & Lazy Load](https://wordpress.org/plugins/ajax-load-more/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ajax-load-more/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ajax-load-more/)
 * [Active Topics](https://wordpress.org/support/plugin/ajax-load-more/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ajax-load-more/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ajax-load-more/reviews/)

## Tags

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

 * 14 replies
 * 2 participants
 * Last reply from: [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/shortcode-parameters-not-working-1/#post-6736712)
 * Status: resolved