Post by catergory brings in extra posts

Have this code

<ul>
		<?php 
		
		$args = array( 'posts_per_page' => -1,  
				'category' => 'locations' 
		);

		$myposts = get_posts( $args );
		foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
		<li>
			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
			<?php the_content(); ?>
		</li>
		<?php endforeach; 
		wp_reset_postdata();?>

works. but instead of only bringing in the post w/category of locations it also brings in extra posts. Have put in something wrong?
thx

In your $args array, the category parameter takes the category id, not the category name. You could use the parameter category_name instead if you want.

will try it. meanwhile i switch to creating a post type for it. But my for loop in content-locations.php is failing.

<article id="locations" class="locations">
		<ul>
		<?php 
		
		$args = array( 
			'post_type' => 'locations' 
			'posts_per_page' => -1,  
				);

		$myposts = get_posts( $args );
		foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
		<li>
			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
			<?php the_content(); ?>
		</li>
		<?php endforeach; 
		wp_reset_postdata();?>
		</ul>
	</article>

arghhh hate idiot moments!
the coma after


'post_type' => 'locations',

was missing.

https://codex.wordpress.org/Function_Reference/setup_postdata

Under the heading Parameters, check out the use of global $post and why.

All right thx appreciate it!
D

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.