• Resolved PuNK DeSi

    (@ades_ting)


    Earlier M using this query to select a specific post and display in sidebar

    $recent = new WP_Query('name=_______');
    while($recent->have_posts()) : $recent->the_post();?>

    By this I need to change name of post after few days to change the post in sidebar. What I want to do I to select three posts and display on date basis in sidebar

    if($today>1 || $today <10) { $mypost = "  "; }
    else if($today >10 || $today <20 {$mypost = " "; }
    else { $mypost = " "; }

    & assign $mypost to query but when I add $mypost variable in this line Its not working…

    $recent = new WP_Query('name=$mypost');
    OR
    $myquery = "name=".$mypost;
    OR $recent = new WP_Query('$myquery');
    OR $recent = new WP_Query('.$myquery.');

    What is the proper way to use variable in WP Query

Viewing 2 replies - 1 through 2 (of 2 total)
  • for instance:

    $recent = new WP_Query('name='.$mypost);

    or:

    $myquery = "name=".$mypost;
    $recent = new WP_Query($myquery);

    also, your logics are false; try:

    if($today>=1 && $today <10) { $mypost = "  "; }
    else if($today >=10 && $today <20 {$mypost = " "; }
    else { $mypost = " "; }
    Thread Starter PuNK DeSi

    (@ades_ting)

    thanks alchymyth

    yeah that logic was not from my actual code I dnt have php files now so put example as my main focus was on how to assign variable to query.
    : Thanks a lot ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPress query on basis of variable date’ is closed to new replies.