Last active
October 25, 2017 15:04
-
-
Save adamculpepper/8759a4cd1e5008c4c4738f59fa65467c to your computer and use it in GitHub Desktop.
Random Wordpress snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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