Make WordPress Core

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#14300 closed defect (bug) (invalid)

shortcodes aren't being substituted when query_posts is used to specify the category

Reported by: mirmillo Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Shortcodes Keywords: shortcodes, query_posts
Focuses: Cc:


When using query_posts() and get_template_part() shortcodes are not being applied to the content, but are being intercepted and removed.

Steps to reproduce:

  1. Create a simple shortcode in your functions.php file something like:
// [thisstinks]
function thisstinks(){
        $html = "<strong>This stinks</strong>";
        return $html;
add_shortcode('thisstinks', 'thisstinks');
  1. create a new post and use the shortcode.
  1. now change the index.php template file to only pull posts from the category as created in step 2. So, in my case, I put that post in the Uncategorized Category and changed index.php to look like:
 query_posts(array('category__in' => array(1)));
 get_template_part( 'loop', 'index' );
  1. try other query_post syntax like: query_post('cat=1');
  1. verify the shortcode is not being substituted.

They do work however, when excluding a category:

query_posts(array('category__not_in' => array(5)));
get_template_part( 'loop', 'index' );

I've duplicated this on multiple sites, including a fresh install of 3.0 with TwentyTen.

Change History (5)

#1 @mirmillo
11 years ago

Here's a better example.

  1. Make a post with a shortcode and put it in the uncategorized category.
  2. Change index.php loop to look like:
query_posts(array('category__in' => array(1)));
get_template_part( 'loop', 'index' );

query_posts(array('category__not_in' => array(2)));
get_template_part( 'loop', 'index' );
  1. View the index page. You'll see the same post twice, only the second one has the shortcode substitution.

#2 @dd32
11 years ago

This actually highlights a bug, Not in the shortcode system, but in the templating system.

Shortcodes are not parsed in excerpt's, They're striped from them instead.

Whats happening here, Is Twentyten treats archives as a the_excerpt(), and treats non-archives as the_content();, WordPress doesnt count the 2nd example as being an "archive" (is_archive() == true).

Now, The reasoning why shortcodes are not in the except, Generally, Excepts are sub-50 words, You cant just throw a video HTML embed in one of those, nor can you expand many shortcodes to that length. Its designed to hold pure plain text.

#4 @markjaquith
10 years ago

  • Resolution set to invalid
  • Status changed from new to closed

This is expected behavior for the_excerpt()

#5 @nacin
10 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.