WordPress.org

Forums

[resolved] Wp_query and variables (4 posts)

  1. Carlo
    Member
    Posted 3 years ago #

    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!

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    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();?>
  3. Carlo
    Member
    Posted 3 years ago #

    Great! Thank you!

  4. keesiemeijer
    moderator
    Posted 3 years ago #

    No problem. Glad you got it resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic