How do I hide posts in a category from all listings but still allow the posts to be viewed?
Answering my own question here: Is it really as easy as including this within a pre_get_posts filter? $query->set(‘category__not_in’, $term_id);
Answering my own question here: Is it really as easy as including this within a pre_get_posts filter? $query->set(‘category__not_in’, $term_id);
Well first off, that code’s a mess to read, some formatting would definitely help get you an answer. That said, here’s the documentation on WP_Query and some sample code to boot $args = array( ‘post_status’ => ‘publish’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => ‘your_cat_slug’ ) ) ); $posts = … Read more
Before the start of your loop on single.php, add this code to check the current post against the fifth most recent post date. If the current post is more recent than fifth, show the post, and if older, show a message that has to do with being loggedin/a member. global $post; $tmp_post = $post; // … Read more
By default, the category with lowest ID is used. If you want control over what the category is, you can try the Hikari Category Permalink plugin, which allows you to choose which post category is used for the permalink. http://wordpress.org/extend/plugins/hikari-category-permalink/
If you are in a category context this should work and and you’ll get the correct catID to work with. function getCurrentCatID(){ global $wp_query; if(is_category()){ $cat_ID = get_query_var(‘cat’); } return $cat_ID; } $catID = getCurrentCatID();
This is the answer 🙂 <?php if (in_category(array(‘News’, ‘Events’))) : ?>
menardmam, this is my solution: <?php $showPostsInCategory = new WP_Query(); $showPostsInCategory->query(‘cat=”. $carouselCategory .”&showposts=”. $carouselNumber .”‘); if ($showPostsInCategory->have_posts()) : while ($showPostsInCategory->have_posts()) : $showPostsInCategory->the_post(); ?> <li> <?php $data = get_post_meta( $post->ID, ‘key’, true ); ?> <?php foreach((get_the_category()) as $category) {echo ( $category->cat_name != $carouselCategory ) ? $category->cat_name . ‘ ‘ : ”;}?> <a href=”https://wordpress.stackexchange.com/questions/45198/<?php if ($data[“custom_link’ ]) … Read more
Ask get_terms() for the ‘link_category’ and restrict the returned fields to IDs: get_terms( ‘link_category’, array ( ‘fields’ => ‘ids’ ) );
I had some trouble saving custom taxonomy fields, which I resolved in this WPSE post. I was using the options table to save my data, but the same solutions may apply for you too. Firing callbacks attached to create_{taxonomy} and edited_{taxonomy} were part of the solution.
Add a check wherever you’re displaying the title: //Anything greater than 0 means the category has parents, 0 means no parent, child category if($category->category_parent > 0){ echo $category[0]->cat_name; } This should help.