2

i created a themes CPT using the following code

function pp_themes_post_type() {
    $args = array(
        'public'       => true,
        'label'        => 'ProfilePress Themes',
        'has_archive'  => true,
        'hierarchical' => true,
        'supports'     => array( 'title', 'editor', 'page-attributes', 'revisions', 'thumbnail' ),
        'taxonomies'   => array( 'category', 'post_tag' )
    );
    register_post_type( 'themes', $args );
}

add_action( 'init', 'pp_themes_post_type' );

I then created a archive-themes.php template file containing the following code that displays Easy digital downloads products categorized as theme.

$paged = get_query_var( 'paged', 1 );


$args = array(
    'post_type'      => 'download',
    'offset'         => 0,
    'paged'          => $paged,
    'posts_per_page' => $posts_per_page,
    'tax_query'      => array(
        array(
            'taxonomy' => 'download_category',
            'field'    => 'slug',
            'terms'    => 'theme' //if field is ID you can reference by cat/term number
        )
    ),
);

$wp_query = new WP_Query( $args );

Viewing the themes CPT output the edd products categorized as theme (see http://profilepress.net/themes/)

The problem arise when you try to goto the next page which 404. (see http://profilepress.net/themes/page/2 ) I installed What Template File Am I Viewing? plugin and discovered the archive-themes.php template isn't used when viewing page 2.

I need all the help i can.

  • just a quick idea: it might help to re-render the URL aliases. I usually do this the quick and dirty way by going to Settings > Permalinks –– then I change the "Common Settings", hit "Save Changes" and then change them back and hit "Save Changes" again. – tillinberlin Oct 2 '15 at 11:01
  • Tried that multiple times.. didn't work. – Collizo4sky Oct 2 '15 at 11:07
  • Sorry but I think you are doing it really wrong. You don't need any custom post type and any custom WP_Query. Why don't use the already existant taxonomy archive template? You can customize the archive template for that taxonomy by creating the template taxonomy-download_category.php and work there with a normal loop. Even you can customize the template for theme term with the file taxonomy-download_category-theme.php. More in template hierarchy. – cybmeta Oct 2 '15 at 11:25
  • I have gone too far with this approach to go back. Is there way i can override the main query when a paginated page is being viewed before it 404? If there is point me to it. with that i can replace it with the query of my choice. – Collizo4sky Oct 2 '15 at 14:01
  • I finally ended up building my own pagination system using query string ?page=2 for detecting next page offset. – Collizo4sky Oct 2 '15 at 16:23
0

there is no need to handle the pagination like this:

$paged = get_query_var( 'paged', 1 );

Just put this after the loop:

get_the_posts_pagination(
    'mid_size'              => 1,
    'prev_text'             => ' ',
    'next_text'             => ' ',
    'screen_reader_text'    => 'A'
)

like this:

if( have_posts() ){
    while( have_posts() ){
        the_post();?>
        the_content();?>
    <?php }
    echo get_the_posts_pagination(
        'mid_size'              => 1,
        'prev_text'             => '&nbsp;',
        'next_text'             => '&nbsp;',
        'screen_reader_text'    => 'A'
    );
    wp_reset_postdata();
}?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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