Skip to main content
added 12 characters in body
Source Link
Charles Clarkson
  • 3.7k
  • 1
  • 18
  • 19

The variable $theTitle is not interpolated in a single quote string.

query_posts('category_name=.$theTitle&orderby=rand');

Will ask for exactly that string. $theTitle will not be replaced with a title and the dot (.) will remain in the query. The result will be unpredictable.

So, use a double quoted string:

query_posts( "category_name={$theTitle}&orderby=rand" );

Or change the order of the arguments and concatenate the title.

query_posts( 'orderby=rand&category_name=' . $theTitle );

Are you sure you want to use query_posts() in an assignment? Isn't kind of like telling the teacher you didn't read the documentation which pretty much says "don't use query_posts()".


EDIT:

Apparently, the query_posts() function uses the parameters for WP_Query which makes sense.

The instructions say that you should use the category slug, not category name: category_name (string) - use category slug (NOT name). I have no idea why they would not name the paramteter category_slug

So first we need to get the category slug.

function wpse_100126_get_category_slug() {

    $current_cat = get_category( get_query_var( 'cat' ) );

    return $current_cat->slug;
}

Then plug that into the query:

query_posts( 'orderby=rand&category_name=' . get_category_slugwpse_100126_get_category_slug() );

The variable $theTitle is not interpolated in a single quote string.

query_posts('category_name=.$theTitle&orderby=rand');

Will ask for exactly that string. $theTitle will not be replaced with a title and the dot (.) will remain in the query. The result will be unpredictable.

So, use a double quoted string:

query_posts( "category_name={$theTitle}&orderby=rand" );

Or change the order of the arguments and concatenate the title.

query_posts( 'orderby=rand&category_name=' . $theTitle );

Are you sure you want to use query_posts() in an assignment? Isn't kind of like telling the teacher you didn't read the documentation which pretty much says "don't use query_posts()".


EDIT:

Apparently, the query_posts() function uses the parameters for WP_Query which makes sense.

The instructions say that you should use the category slug, not category name: category_name (string) - use category slug (NOT name). I have no idea why they would not name the paramteter category_slug

So first we need to get the category slug.

function wpse_100126_get_category_slug() {

    $current_cat = get_category( get_query_var( 'cat' ) );

    return $current_cat->slug;
}

Then plug that into the query:

query_posts( 'orderby=rand&category_name=' . get_category_slug() );

The variable $theTitle is not interpolated in a single quote string.

query_posts('category_name=.$theTitle&orderby=rand');

Will ask for exactly that string. $theTitle will not be replaced with a title and the dot (.) will remain in the query. The result will be unpredictable.

So, use a double quoted string:

query_posts( "category_name={$theTitle}&orderby=rand" );

Or change the order of the arguments and concatenate the title.

query_posts( 'orderby=rand&category_name=' . $theTitle );

Are you sure you want to use query_posts() in an assignment? Isn't kind of like telling the teacher you didn't read the documentation which pretty much says "don't use query_posts()".


EDIT:

Apparently, the query_posts() function uses the parameters for WP_Query which makes sense.

The instructions say that you should use the category slug, not category name: category_name (string) - use category slug (NOT name). I have no idea why they would not name the paramteter category_slug

So first we need to get the category slug.

function wpse_100126_get_category_slug() {

    $current_cat = get_category( get_query_var( 'cat' ) );

    return $current_cat->slug;
}

Then plug that into the query:

query_posts( 'orderby=rand&category_name=' . wpse_100126_get_category_slug() );
added 720 characters in body
Source Link
Charles Clarkson
  • 3.7k
  • 1
  • 18
  • 19

The variable $theTitle is not interpolated in a single quote string.

query_posts('category_name=.$theTitle&orderby=rand');

Will ask for exactly that string. $theTitle will not be replaced with a title and the dot (.) will remain in the query. The result will be unpredictable.

So, use a double quoted string:

query_posts( "category_name={$theTitle}&orderby=rand" );

Or change the order of the arguments and concatenate the title.

query_posts( 'orderby=rand&category_name=' . $theTitle );

Are you sure you want to use query_posts() in an assignment? Isn't kind of like telling the teacher you didn't read the documentation which pretty much says "don't use query_posts()".


EDIT:

Apparently, the query_posts() function uses the parameters for WP_Query which makes sense.

The instructions say that you should use the category slug, not category name: category_name (string) - use category slug (NOT name). I have no idea why they would not name the paramteter category_slug

So first we need to get the category slug.

function wpse_100126_get_category_slug() {

    $current_cat = get_category( get_query_var( 'cat' ) );

    return $current_cat->slug;
}

Then plug that into the query:

query_posts( 'orderby=rand&category_name=' . get_category_slug() );

The variable $theTitle is not interpolated in a single quote string.

query_posts('category_name=.$theTitle&orderby=rand');

Will ask for exactly that string. $theTitle will not be replaced with a title and the dot (.) will remain in the query. The result will be unpredictable.

So, use a double quoted string:

query_posts( "category_name={$theTitle}&orderby=rand" );

Or change the order of the arguments and concatenate the title.

query_posts( 'orderby=rand&category_name=' . $theTitle );

Are you sure you want to use query_posts() in an assignment? Isn't kind of like telling the teacher you didn't read the documentation which pretty much says "don't use query_posts()".

The variable $theTitle is not interpolated in a single quote string.

query_posts('category_name=.$theTitle&orderby=rand');

Will ask for exactly that string. $theTitle will not be replaced with a title and the dot (.) will remain in the query. The result will be unpredictable.

So, use a double quoted string:

query_posts( "category_name={$theTitle}&orderby=rand" );

Or change the order of the arguments and concatenate the title.

query_posts( 'orderby=rand&category_name=' . $theTitle );

Are you sure you want to use query_posts() in an assignment? Isn't kind of like telling the teacher you didn't read the documentation which pretty much says "don't use query_posts()".


EDIT:

Apparently, the query_posts() function uses the parameters for WP_Query which makes sense.

The instructions say that you should use the category slug, not category name: category_name (string) - use category slug (NOT name). I have no idea why they would not name the paramteter category_slug

So first we need to get the category slug.

function wpse_100126_get_category_slug() {

    $current_cat = get_category( get_query_var( 'cat' ) );

    return $current_cat->slug;
}

Then plug that into the query:

query_posts( 'orderby=rand&category_name=' . get_category_slug() );
Source Link
Charles Clarkson
  • 3.7k
  • 1
  • 18
  • 19

The variable $theTitle is not interpolated in a single quote string.

query_posts('category_name=.$theTitle&orderby=rand');

Will ask for exactly that string. $theTitle will not be replaced with a title and the dot (.) will remain in the query. The result will be unpredictable.

So, use a double quoted string:

query_posts( "category_name={$theTitle}&orderby=rand" );

Or change the order of the arguments and concatenate the title.

query_posts( 'orderby=rand&category_name=' . $theTitle );

Are you sure you want to use query_posts() in an assignment? Isn't kind of like telling the teacher you didn't read the documentation which pretty much says "don't use query_posts()".