it loops correctly 10 times but with wrong content. it alloys using the content with id 11
show_posts with 10 posts (thats correct) but always first content
my function show_posts
in Theme.php
:
public function show_posts() { # show_posts220914() {
$args = array(
'numberposts' => 200
);
$my_posts = get_posts( $args );
if( ! empty( $my_posts ) ){
foreach ( $my_posts as $post ){
get_template_part( 'content','content');
}
}
}
so result in http://localhost/wordpress/ is
<li>11</li><li>11</li><li>11</li><li>11</li><li>11</li><li>11</li><li>11</li><li>11</li><li>11</li><li>11</li>
show_posts with correct constant but to less posts:
in this next try i have correct constant but to less posts:
public function show_posts(){
global $wp_query;
$args = array_merge( $wp_query->query_vars, ['posts_per_page' => 200 ] ); # has no effect here
query_posts( $args ); # has no effect here
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$post= the_post();
get_template_part( 'content','content');
endwhile;
endif;
}
so result in http://localhost/wordpress/ is
<li>11</li><li>12</li><li>13</li><li>14</li><li></li>
my content.php
:
<li>
<?php the_title(); ?>
</li>
my home.php
:
<ol>
<?php
do_action( 'home_content' );
?>
</ol>
i call it with http://localhost/wordpress/.
i don’t use any pages. means http://localhost/wordpress/wp-admin/edit.php?post_type=page tells me No pages found
.
i found inspiration here:
i using WordPress 6.0.2
any idea?
2
Answers
i get this correct output
if i use this:
Theme.php
:content.php
:functions.php
:home.php
:it helps me reading this: What is the real purpose of magic method __set_state in PHP? and the use of the var_export command sometimes
Your second WordPress loop looks like it could almost work … I’m not sure what
$wp_query->query_vars
could contain that you are merging with yourpost_per_page
constraint.Try this, more standard loop (and/or read about the loop on WordPress’ Codex):