• Resolved tiaanswart

    (@tiaanswart)


    Hi

    I created a custom post type ‘portfolio’ and created a page called portfolio in the page I want to display all posts for this post type so I added 2 queries, one is for showing all custom taxonomy entries for ‘skills’ linked to the post type the other displays the posts.

    <div id="content-portfolio">
    
        <div class="filterSkills">
            <?php
    
                //List all the terms in a skills taxonomy, without a link
    
                $terms = get_terms("Skills");
                $count = count($terms);
                if ( $count > 0 ){
    
                    echo 'Showing all Portfolio Items in the following skill sets:';
    
                    foreach ( $terms as $term ) {
                        echo ' <a href="' .get_bloginfo('url'). '/skills/' . $term->slug . '/" class="' . $term->slug . '" title="List all ' . $term->name . ' items">' . $term->name . '</a>';
    
                    }
                }
    
            ?>
        </div>
    
        <?php
    
            $limit = get_option('posts_per_page');
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
            query_posts('showposts=' . $limit . '&paged=' . $paged .'&post_type=portfolio');
    
            $wp_query->is_archive = true; $wp_query->is_home = false;
        ?>
    
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
        <!-- POST START --><br/>
        <div class="post">
            <!-- ENTRY START -->
    		<div class="date">
    		    <p>Posted on <span style="font-weight: bold;"><?php the_time( 'D d M Y ' ); ?></span> (about  <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>) by <span style="font-weight: bold;"><?php the_author_link(); ?></span></p>
    		</div>
            <div class="entry">
    			<h2 class="title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		</div>
            <!-- ENTRY END -->
    	</div>
        <!-- POST END -->
    
        <?php endwhile; ?>
    
        <!-- Page Navigation -->
        <?php if (function_exists('wp_pagenavi')) : ?>
        <div class="pagenavi">
            <?php wp_pagenavi(); ?>
        </div>
    
        <?php else : // Use WordPress default page navigation. ?>
    
        <div class="pages">
            <span class="older"><?php next_posts_link('&laquo; Older Entries'); ?></span>
            <span class="newer"><?php previous_posts_link('Newer Entries &raquo;'); ?></span>
        </div>
    
        <?php endif; ?>
    
        <?php else : ?>
    
        <p>Sorry, but nothing matched your search criteria.</p>
    
    	<?php get_search_form(); ?>
    
        <?php endif; ?>
    
        </div>

    The post is displayed as well as the ‘older entries’ pagination link, however when the pagination link is clicked a 404 error occurs.

    I used print_r($wp_query); to display the queries on both pages, 404 & portfolio, this is what was returned:

    Portfolio:

    WP_Query Object ( [query_vars] => Array ( [showposts] => 1 [paged] => 1 [post_type] => portfolio [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author_name] => [feed] => [tb] => [comments_popup] => [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [fields] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [ignore_sticky_posts] => [suppress_filters] => [cache_results] => 1 [update_post_term_cache] => 1 [update_post_meta_cache] => 1 [posts_per_page] => 1 [nopaging] => [comments_per_page] => 0 [no_found_rows] => [order] => DESC ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( ) [relation] => AND ) [meta_query] => WP_Meta_Query Object ( [queries] => Array ( ) [relation] => ) [post_count] => 1 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 2 [max_num_pages] => 2 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => 1 [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => [is_404] => [is_comments_popup] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash] => 2742cf66e85801295f90d192b9c874db [query_vars_changed] => [thumbnails_cached] => [query] => Array ( [showposts] => 1 [paged] => 1 [post_type] => portfolio ) [request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'portfolio' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 1 [posts] => Array ( [0] => stdClass Object ( [ID] => 37 [post_author] => 1 [post_date] => 2012-08-21 19:33:08 [post_date_gmt] => 2012-08-21 17:33:08 [post_content] => hello hello [post_title] => test hello [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => test-hello [to_ping] => [pinged] => [post_modified] => 2012-08-25 08:17:41 [post_modified_gmt] => 2012-08-25 06:17:41 [post_content_filtered] => [post_parent] => 0 [guid] => https://localhost:23000/?post_type=portfolio&p=37 [menu_order] => 0 [post_type] => portfolio [post_mime_type] => [comment_count] => 0 [filter] => raw ) ) [post] => stdClass Object ( [ID] => 37 [post_author] => 1 [post_date] => 2012-08-21 19:33:08 [post_date_gmt] => 2012-08-21 17:33:08 [post_content] => hello hello [post_title] => test hello [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => test-hello [to_ping] => [pinged] => [post_modified] => 2012-08-25 08:17:41 [post_modified_gmt] => 2012-08-25 06:17:41 [post_content_filtered] => [post_parent] => 0 [guid] => https://localhost:23000/?post_type=portfolio&p=37 [menu_order] => 0 [post_type] => portfolio [post_mime_type] => [comment_count] => 0 [filter] => raw ) )

    404:

    WP_Query Object ( [query_vars] => Array ( [page] => 2 [portfolio] => page [post_type] => portfolio [name] => page [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author_name] => [feed] => [tb] => [paged] => 0 [comments_popup] => [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [fields] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [ignore_sticky_posts] => [suppress_filters] => [cache_results] => 1 [update_post_term_cache] => 1 [update_post_meta_cache] => 1 [posts_per_page] => 1 [nopaging] => [comments_per_page] => 0 [no_found_rows] => [order] => DESC ) [tax_query] => [meta_query] => WP_Meta_Query Object ( [queries] => Array ( ) [relation] => ) [post_count] => 0 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => [is_404] => 1 [is_comments_popup] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash] => 94bef5fa2659ec263e682cd102950f11 [query_vars_changed] => [thumbnails_cached] => [query] => Array ( [page] => /2 [portfolio] => page [post_type] => portfolio [name] => page ) [request] => SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_name = 'page' AND wp_posts.post_type = 'portfolio' ORDER BY wp_posts.post_date DESC [posts] => Array ( ) [queried_object] => [queried_object_id] => 0 )

    Please someone help?

    I have tried to find a possible solution on the web however none has worked so far?

    Thanks!

Viewing 15 replies - 1 through 15 (of 15 total)
  • Because the 404 request shows AND wp_posts.post_name = 'page', I am guessing that something is incorrect with your permalinks and that the URL for the ‘older entries’ looks something like this:

    https://yoursite.com/portfolio/page/2

    Try resetting your permalinks.

    Note the current setting, set to the default, save, and set back to the current setting.

    A link to your site where the ‘older entries’ can be seen might save some guesswork.

    BTW, you can see just the SQL with print_r($wp_query->request);.

    Thread Starter tiaanswart

    (@tiaanswart)

    Thanks vtxyzzy. I reset the permalinks and yes the link for page 2 is https://localhost:23000/portfolio/page/2/, sadly however the reset did not work still get a 404 error.

    Do you happen to have a portfolio record titled ‘Page’?

    Thread Starter tiaanswart

    (@tiaanswart)

    Nope one i only have 2 posts ‘test hello’ and ‘test 2’

    What do you get when you try the address https://localhost:23000/portfolio/?paged=2

    Thread Starter tiaanswart

    (@tiaanswart)

    OMW!!!! that worked?? *Jumping for joy!*

    So what is wrong?

    There is still something not correct with the permalinks, although I can’t say what. Many times resetting the permalinks will fix the problem.

    Try setting them to the default and leaving it there to see if that works.

    That is not a long term solution, but might give a clue to what is happening.

    Thread Starter tiaanswart

    (@tiaanswart)

    Reset the permalinks to default, this messed up my ajax so i removed my ajax scripts

    Thread Starter tiaanswart

    (@tiaanswart)

    So is there someway i can find the error/issue with the permalinks?

    So did the default work after removing the ajax? If so, try the pretty permalinks again.

    Thread Starter tiaanswart

    (@tiaanswart)

    Yes it worked.

    I tried the pretty permalinks again and it didn’t work

    Do you know if you have mod_rewrite enabled in your server?

    If you don’t know how to find out, install the Phpinfo plugin, run it and look for mod_rewrite under Configuration->Loaded Modules.

    Thread Starter tiaanswart

    (@tiaanswart)

    Thanks for that…

    Ok i checked and did not see the mod_rewrite variable?

    I run IIS 7 Web Matrix 2, i checked the url rewrite extension to iis 7 and its up to date and seems to be working as should?

    Sorry, but I do not know IIS, only Apache, so you will need to find someone else to help with this.

    Thread Starter tiaanswart

    (@tiaanswart)

    Thanks a mill for all the help!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Custom Post Type Query_Posts Pagination 404 Error’ is closed to new replies.