• Resolved Anonymous User 7476186

    (@anonymized-7476186)


    Hi!
    Just to put it simple, i’ve a Wp_query declaration like this:
    <?php $recent = new WP_Query("category_name=xyz&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    and i want to replace the category name with a variable, this one;
    <?php echo ($title1) ? stripslashes($title1) : “”;?>

    How can i merge the codes and make this happen?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    try it with this [untested]:

    <?php
    $title1 = ($title1) ? '&category_name='.stripslashes($title1) : "";
    $recent = new WP_Query("posts_per_page=1".$title1); while($recent->have_posts()) : $recent->the_post();?>

    Thread Starter Anonymous User 7476186

    (@anonymized-7476186)

    Great! Thank you!

    Moderator keesiemeijer

    (@keesiemeijer)

    No problem. Glad you got it resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Wp_query and variables’ is closed to new replies.