WordPress.org

Ready to get started?Download WordPress

Forums

Filtering Category problems (2 posts)

  1. alexDevMilagro
    Member
    Posted 3 years ago #

    Here we go.

    This is the blog: http://demo.kngfu.com/milagro

    If you click a category, ie. Media. You are brought the category.php page. All is ok, BUT the categories are not filtering. I've tried these various snippets to get it functioning, to no avail.

    //this is the current block being run atm, the category_name param is //just a test, which is failing, it's just showing ALL category posts
    //i'm not an avid php'er so i'm not sure if that syntax is correct
    <h1>Category: <a href="<?php the_permalink();?>"><?php $theTitle = single_cat_title(); ?></a></h1>
    <?php query_posts('category_name='.$theTitle);?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                   ......content.......
    <?php endwhile; ?>
    <?php endif; ?>

    As you can see, the single_cat_title() function is working, yet I can't get an accurate query of posts per cat.

    This is using the WP_Query object, but still failing.

    <?php
      <h1>Category: <a href="<?php the_permalink();?>"><?php $theTitle = single_cat_title(); ?></a></h1>
      $_posts= new WP_Query('category='.$theTitle);
      if($_posts->have_posts()) : while($_posts->have_posts()) : $_posts-  >the_post();
      if($post->ID == $no_duplicate) continue;
      update_post_caches($posts);
    
    ?>
    ......content.......
    <?php endwhile; ?>
    <?php endif; ?>

    Either way, I'm sure someone here has a quick solution, let me know.

    I'm also having problems with new posts in my Dashboard, my new posts wont appear. Also, I can't filter for certain categories in my Categories section in wp-admin.php yet all the posts I'm looking for are in my database under the correct category!

    Not sure if these are related, but I figure they would be.

    Thanks!

    PS: Feel free to critique the site, it's my first WP site!

  2. alexDevMilagro
    Member
    Posted 3 years ago #

    I'm also having problems with new posts in my Dashboard, my new posts wont appear. Also, I can't filter for certain categories in my Categories section in wp-admin.php yet all the posts I'm looking for are in my database under the correct category!

    Turns out my code in functions.php:

    function exclude_category($query) {
    	if ( $query->index.php ) {
    		$query->set('cat', '-101', '-41');
    	}
    	return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    Was hiding my categories in question from index.php AND edit.php, so I just went and the go RYO 'Category Visibility' plugin. Works like a charm, now the other problem.. Any guesses?

Topic Closed

This topic has been closed to new replies.

About this Topic