1

I have a custom post type of Textorial with necessary template files:

  1. textorial-type.php
  2. single-textorial.php
  3. content-textorial.php

The idea is to have a custom layout for the post type and use infinite-scroll to pull them in. That's why I'm using content.php. I got the infinite-scroll set up,and succesfully tested with regular posts. But when pulling custom post type in on index.php:

<div id="content">
<?php 
    while (have_posts()) : the_post();
        get_template_part( 'content', 'textorial' );                    
    endwhile;   
?>
</div>

... nothing shows up. Also no errors. But the single-textorial.php is using the same method and its content is showing. Any ideas?

Update!

on front-page.php:

<?php $args = array('post_type' => 'textorial');
                $query = new WP_Query( $args );
                while (have_posts() ) : the_post();
                    get_template_part( 'content', 'textorial' );
                endwhile; 
              ?>

But now only regular posts show up.

7
  • Did you use pre_get_posts to set your custom post type in the main query. Also, what is texorial-type.php Jan 28, 2015 at 12:15
  • I don't follow you when say main query, you are looking at the main query. Doesn't it know to pick up textorial post-type without it? textorial-type.php is the file where I declare the custom post type and control its parameters.
    – Laniakea
    Jan 28, 2015 at 12:34
  • Ha, that confused me, so textorial-type.php is like a functions.php file. Remember, custom post types are excluded from the main query Jan 28, 2015 at 12:37
  • Yeah, I keep them separate for code reading purposes. I tried query know, please see update.
    – Laniakea
    Jan 28, 2015 at 12:48
  • On which specific page/template are you trying this Jan 28, 2015 at 12:52

1 Answer 1

5

You have a couple of issues with your code.

  • You have to set your loop to your custom query. As it stands, it is set to the main query

  • You must always reset postdata with all instances of WP_Query

Your code should be something like this

<?php $args = array('post_type' => 'textorial');
$query = new WP_Query( $args );
while ($query->have_posts() ) : $query->the_post();

    get_template_part( 'content', 'textorial' );

endwhile; 
wp_reset_postdata(); ?>
2
  • Yeah, custom posts are now showing up. Thank you for your input.
    – Laniakea
    Jan 28, 2015 at 13:59
  • Glad it worked. Enjoy :-) Jan 28, 2015 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.