Skip to content

Instantly share code, notes, and snippets.

@gregrickaby
Last active November 26, 2018 01:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gregrickaby/e3b3e7982f6a4c42f3a8c27b4e18bcda to your computer and use it in GitHub Desktop.
Save gregrickaby/e3b3e7982f6a4c42f3a8c27b4e18bcda to your computer and use it in GitHub Desktop.
WordPress get category ID
<?php
// Get the "featured" category object.
$featured_category = get_term_by( 'slug', 'featured', 'category' );
// Set the "featured" category ID.
$featured_category_ID = $featured_category->term_id;
// Get the latest three posts, ignoring the current post
// and any in the "featured" category.
$args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'post__not_in' => array( get_the_ID() ),
'category__not_in' => array( absint( $featured_category_ID ) ),
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
);
// Run query.
$data = new WP_Query( $args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment