Mistake in Codex page?
-
The “Note for Multiple Posts in the First Category” in the this page:
https://codex.www.ads-software.com/The_Loop
is clearly wrong.Can anyone tell me what it should be?
If showposts=2 or more, you will need to alter the code a bit. The variable $do_not_duplicate needs to be changed into an array as opposed to a single value. Otherwise, the first loop will finish and the variable $do_not_duplicate will equal only the id of the latest post. This will result in duplicated posts in the second loop. To fix the problem replace <?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?> with <?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate[] ) continue; update_post_caches($posts); ?> This changes $do_not_duplicate into an array. Then replace <?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?> with <?php if (have_posts()) : while (have_posts()) : the_post(); if($post->ID == $do_not_duplicate[0] || $post->ID == $do_not_duplicate[1] || $post->ID == $do_not_duplicate[2]) continue; update_post_caches($posts); ?> (Or use php's in_array().) Where you continue the pattern for whatever showposts is set equal to (2 in this case).
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Mistake in Codex page?’ is closed to new replies.