Skip to content

Instantly share code, notes, and snippets.

@adamculpepper
Last active October 25, 2017 15:04
Show Gist options
  • Save adamculpepper/8759a4cd1e5008c4c4738f59fa65467c to your computer and use it in GitHub Desktop.
Save adamculpepper/8759a4cd1e5008c4c4738f59fa65467c to your computer and use it in GitHub Desktop.
Random Wordpress snippets
get_category($category_id)->count //items in category
//just posts in category
$query = new WP_Query( array('posts_per_page' => -1, 'category__in' => $category) );
$count = $query->post_count;
echo 'count: ' . $count;
INSIDE LOOP
the_permalink(); get_the_permalink();
the_title(); get_the_title();
the_date(); get_the_date();
the_content(); get_the_content();
THE LOOP:
<?php
global $post;
$args = array( 'posts_per_page' => -1, 'posts_per_page' => 5, 'category__in' => $category_id);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) :
setup_postdata( $post );
?>
<?php the_title(); ?>
<?php endforeach;
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment