• Resolved kirasiris

    (@kirasiris)


    So this is the first time in which something like this happens to me. I’ve used the same method in some of my last projects and it works well but in the current template in which I’m working it is not.

    Here is the custom page that displays the custom post type(snippets):

    <?php
    /*
    Template Name: Snippets
    Template Post Type: page
    */
    ?>
    <?php get_header(); ?>
    <?php include("includes/page-header.php"); ?>
    <div class="container">
        <!-- Page Heading -->
        <div class="row">
    		<div class="col-md-12">
                <div class="pull-left">
                    <button class="btn btn-sm btn-default" data-toggle="portfilter" data-target="all">All</button>
    					<?php 
                            $terms = get_terms("snippets_categories"); // Consigue todas las categorias del custom taxonomy.
                            $termsString .=  $term->slug;
                            $count = count($terms); //Cuantos categorias son?
                            if ( $count > 0 ){  //Si es que hay mas de uno
                                foreach ( $terms as $term ) {  //Para cada termino:
                                    echo "<button class='btn btn-sm btn-primary' data-toggle='portfilter' data-target='".$term->slug."'>".$term->name."</button>\n";
                                }
                            } 
                        ?>
                </div>
    		<div class="clearfix"></div>
    		<?php 
    			$snippets_query = new WP_Query(array(
    				'post_type' => 'snippets',
    				'order' => 'DESC',
    			));
    		?>
    		<?php if($snippets_query->have_posts()) : while($snippets_query->have_posts()) : $snippets_query->the_post();?>
    			<?php $terms_snippets = get_the_terms( get_the_ID(' '), 'snippets_categories'); ?>
                <?php
    				$terms_snippet_slugs = array();
    				foreach ($terms_snippets as $tp) {
    					$terms_snippet_slugs[] = $tp->slug;
    				}
    				$terms_snippet_csv = implode (' ',$terms_snippet_slugs);
    			?>
            	<a class="snippet" href="<?php the_permalink(); ?>" data-tag="<?php echo $terms_snippet_csv; ?>"><?php the_title(); ?></a>
    		<?php endwhile; ?>
    		<?php  else : ?>
            	<div class="alert alert-danger text-center"><p>Ningun snippet encontrado</p></div>
    		<?php endif; ?>
    		</div>
        </div>
    </div><!-- /Container --->
    <!-- /.row -->
    <?php get_footer(); ?>

    This is my problem, I currently have 12 published posts. 2 with the category of Javascript, 2 others with the category of CodeIgniter, and 8 posts with the category of WordPress. I don’t know what the problem is but all the posts with the category of WordPress are not displayed in the custom page.

    Any idea on how to fix this? Thanks is advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Did you change any of your site URL value.

    also :
    I suggest you log all your SQL queries and see what queries are getting generated.
    This will help you know what filters are resulting in that specific category post not considered.

    Moderator bcworkz

    (@bcworkz)

    magentomaster is correct. There is a filter callback somewhere that is taking the WordPress category term out of the query. I’m not sure how logging SQL would help you find the filter hook responsible. What I would do is narrow down the source to a particular theme or plugin. The troubleshooting mode of the health-check plugin is useful for this.

    Once the responsible module is identified, there is a lot less code you need to search through. The most likely action to hook is “pre_get_posts”. Look for code where related query vars are altered, such as “category__not_in” or “tax_query” where the ‘NOT IN’ operator is used.

    Thread Starter kirasiris

    (@kirasiris)

    Hey, I solved it. Silly me… I did not realize that I had setup 5 post per page in the settings>reading>Blog pages show at most.

    After I realize that, I still wanted to show all the CPT posts without limits, so in my custom page I had to edit the query which displays the CPTS by adding this:

    
    $snippets_query = new WP_Query(array(
    	'post_type' => 'snippets',
    	'order' => 'DESC',
    	'posts_per_page' => -1,
    ));
    

    and that fixed it. Thanks for helping. I’m now closing this question as solved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Number of Custom Post Types published are not being shown in the custom page’ is closed to new replies.