Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Multiple WordPress Query WordPress

  • SOLVED

<?php
$count = 0;
$my_query = new WP_Query('category_name=politiki');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;
$count++;
?>
<li>
<?php $field = get_field($videoid); ?>
</li>
<?php if ($count % 2 == 0) { ?>
//do something like displaying an ad

<?php
}
endif;

endwhile;
?>


Hi, i am running the following WordPress query, but i am just getting a blank Page. I would like to see the solution to the problem

Answers (6)

2011-09-22

Julio Potier answers:

Hello
What contains : $videoid ? If it's not set, the field return ''.
Do not forget that you do not ECHO anything !

And after it might be this :
1) The category name is not correct,
2) The field name is not correct,
3) The category is empty,
4) The field is empty.

Is it really a blank page or in source code from web browser you can see "<li></li>" ?

See you


Julio Potier comments:

Try this :
<?php
$count = 0;
$my_query = new WP_Query('category_name=politiki');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;
$count++;
?>
<li>
<?php $field = get_field($videoid); echo $field; ?>
</li>
<?php if ($count % 2 == 0) { ?>
//do something like displaying an ad

<?php
}
endif;

endwhile;
?>


Basilis Kanonidis comments:

Nop, neither category is empty, nor the post field.

There are no <li></li> either.

Julio, i have tried it also, but not working either :-/


Julio Potier comments:

So, can i have a look to the full code, page, website ?
Give me an extra access, i'll look at it.

2011-09-22

John Cotton answers:

You don't output anything other than HTML in the loop!

Try


<li>

<?php echo '1'; $field = get_field($videoid); ?>

</li>


and see whether you get a list of ones. If you do, then you need to decide what you actually want to appear and code to echo that.


Basilis Kanonidis comments:

Have you given a try to the loop? Probably not.

Again with your way, i am still just getting a blank page.

Html would be outputted even if blocks are empty. But something is wrong with the query it self.

2011-09-22

Jens Filipsson answers:

<?php

$count = 0;

$my_query = new WP_Query('category_name=politiki');

while ($my_query->have_posts()) : $my_query->the_post();

$do_not_duplicate = $post->ID;

$count++;

?>

<li>

<?php $field = get_field($videoid); ?>
<?=$field?>

</li>

<?php if ($count % 2 == 0) { ?>

//do something like displaying an ad



<?php

}

endif;



endwhile;

?>


Basilis Kanonidis comments:

Neither that mate :-/

I have removed the count % 2 and the query is been running correctly. Is it possible there is a wrong syntax there?


Jens Filipsson comments:

<?php



$count = 1;



$my_query = new WP_Query('category_name=politiki');



while ($my_query->have_posts()) : $my_query->the_post();



$do_not_duplicate = $post->ID;



?>



<li>



<?php $field = get_field($videoid); ?>

<?=$field?>



</li>



<?php if($count == 2) : ?>



//do something like displaying an ad







<?php endif; $count++;







endwhile;



?>

2011-09-22

Romel Apuya answers:

have you tried adding the wp_reset_query at the end?

it might be the cause.
but ofcourse dont forget to echo the things you need.



<?php

$count = 0;

$my_query = new WP_Query('category_name=politiki');

while ($my_query->have_posts()) : $my_query->the_post();

$do_not_duplicate = $post->ID;

$count++;

?>

<li>

<?php $field = get_field($videoid); ?>

</li>

<?php if ($count % 2 == 0) { ?>

//do something like displaying an ad



<?php

}

endif;



endwhile;
wp_reset_query();

?>

2011-09-22

Abdessamad Idrissi answers:

check this code

<?php

$args = array(
'category_name' => 'politiki'
);

$query = new WP_Query($args);

if( $query ->have_posts() ) {
while ($query->have_posts()) : $query->the_post();
$do_not_duplicate = get_the_ID();
$count++;
?>

<li><?php $field = get_field($videoid); ?></li>
<?php
if ($count % 2 == 0) {
?>
//do something like displaying an ad
<?php
}

endwhile;

} else
{
echo 'Nothing found!';
}

wp_reset_query();
?>


One thing to check is category name must be the slug for that category not its name!

2011-09-22

Luis Abarca answers:

Everything looks right, just check if theres published posts on the category politiki.

Try this one:


<?php
$count = 0;

$my_query = new WP_Query('category_name=politiki');
?>

<?php if ( $my_query->have_posts() ) : ?>

<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

<?php
$do_not_duplicate = $post->ID;
$count++;
?>

<li><?php echo $field = get_field($videoid) ?></li>

<?php if ( $count % 2 == 0 ) : ?>
//do something like displaying an ad
<?php endif ?>

<?php endwhile ?>

<?php endif ?>