I try to learn some basics about WP so I pasted the following code into a WP page where I use a plug-in that allows me to write PHP.
It works for the_title (twice), but when I put the_content inbetween, the page hangs with no output. I must comment the_content to make the page print the_title (twice). Different efforts give the same result: the_content() hangs the page but not the_title().
What do I do wrong using the_content.
Sorry that I have not got the formatting perfect. br1 are break tags enclosed in tags to stop php interpretation
$args = array(
'post_type' => 'post'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
the_title();
br1
// the_content();
br1
the_title();
br1br1
}
}
I try to learn some basics about WP so I pasted the following code into a WP page where I use a plug-in that allows me to write PHP.
It works for the_title (twice), but when I put the_content inbetween, the page hangs with no output. I must comment the_content to make the page print the_title (twice). Different efforts give the same result: the_content() hangs the page but not the_title().
What do I do wrong using the_content.
Sorry that I have not got the formatting perfect. br1 are break tags enclosed in tags to stop php interpretation
$args = array(
'post_type' => 'post'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
the_title();
br1
// the_content();
br1
the_title();
br1br1
}
}
Share
Improve this question
edited Dec 27, 2020 at 5:23
fuxia♦
107k38 gold badges255 silver badges459 bronze badges
asked Dec 27, 2020 at 4:41
cvrcvr
1135 bronze badges
1 Answer
Reset to default 0We can drop this question, please. The page probably loops when it lists itself. I must just find a way to exclude listing itself. Sorry.
This is what was missing
$args = array(
'post_type' => 'post',
'post__not_in' => array(get_the_ID())
);