0
votes

I've got a custom post type I need to set to 'display all posts'. In Reading I've set it to 10 due to only wanting 10 posts on the blog page. How do I set the maximum posts on the CPT page? I've found this code...

$args = array('post_type' => 'portfolio',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'portfolio',
'field' => 'slug',
)
)
)

$query = new WP_Query($args)

I'm new to php so I'm unsure where I add this - functions.php in the 'register CPT' or in the loop on the archive page? The loop is quite complicated as I'm pulling in 3 taxonomies and setting values each time.

<?php $i = 0; ?>
                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                    <?php 
                    $i++;
                    $term_list1 = wp_get_post_terms($post->ID, 'discipline', array("fields" => "ids"));
                    $term_list2 = wp_get_post_terms($post->ID, 'type', array("fields" => "ids")); 
                    $term_list3 = wp_get_post_terms($post->ID, 'sector', array("fields" => "ids")); 
                     ?>

                <li class="item" data-id="id-<?php echo $i; ?>" data-type='<?php foreach ($term_list1 as $value) {echo $value." ";} ?><?php foreach ($term_list2 as $value) {echo $value." ";} ?><?php foreach ($term_list3 as $value) {echo $value." ";} ?>'>
                    <a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>

                </li>

                <?php endwhile; else : ?>
                <?php endif; ?>

Any help would be appreciated, thanks.

2

2 Answers

1
votes

I figured it out, I used this:

<?php $args = array( 'post_type'=>'portfolio', 'posts_per_page'=>100); 
                    $portfolio = new WP_Query( $args ); while( $portfolio->have_posts() ) : $portfolio->the_post(); ?>
0
votes

You need to edit your template, and pass those arguments to the query_posts function BEFORE your loop, then reset the query with wp_reset_query after:

<?php
query_posts( array(
    'post_type' => 'portfolio',
    'posts_per_page' => -1 )
);
$i = 0;
if (have_posts()) : while (have_posts()) :

    the_post();

    $i++;
    $term_list1 = wp_get_post_terms($post->ID, 'discipline', array("fields" => "ids"));
    $term_list2 = wp_get_post_terms($post->ID, 'type', array("fields" => "ids"));
    $term_list3 = wp_get_post_terms($post->ID, 'sector', array("fields" => "ids"));
    ?>

<li class="item" data-id="id-<?php echo $i; ?>" data-type='<?php echo implode(' ',$term_list1 ) . ' ' . implode(' ',$term_list2 ) . ' ' . implode(' ',$term_list3 ); ?>'>
    <a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>

</li>

<?php
endwhile; endif;
wp_reset_query();
?>

I also tided up your data-type generation with the use of implode rather than foreach loops