Community Forums › Forums › Archived Forums › General Discussion › Pagination 404 Issue
Tagged: 404, CPT, pagination
- This topic has 7 replies, 2 voices, and was last updated 8 years, 6 months ago by
Stefaan5.
-
AuthorPosts
-
July 8, 2016 at 1:06 am #189075
Stefaan5
MemberHello,
I am trying to create a paginated loop of testimonials including the title, featured image, excerpt and permalink to the single page.
This is a Custom Post Type made with the plugins CPT UI & ACF. Also, the site is made on a local development environment using MAMP.I was able to create the paginated loop using the snippet from Bill Erickson, which created the following code.
However, even though the pagination does show up, it only leads to 404 pages. This while the original page works fine.I do not have a single idea anymore what the issue could be. Anybody can get me on the right track? Any help will be much appreciated!
//Create Paginated loop for CPT 'getuigenissen'
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action('genesis_loop', 'getuigenissen_loop');function getuigenissen_loop(){
$args = array(
'posts_per_page' => 4,
'post_type' => 'getuigenissen',
'order' => 'DESC',
'order_by' => 'menu_order',
'paged' => get_query_var( 'page' )
);global $wp_query;
$wp_query = new WP_Query( $args );if ( have_posts() ) :
echo '<div id="getuigenissen-container">';
while ( have_posts() ) : the_post();
?><h2><?php the_title(); ?><span> - <?php the_field('adres'); ?></span></h2>
<div class="getuige-imgContainer"><div class="getuigenisImg" style="background-image: url(<?php the_post_thumbnail_url(); ?>);"></div>
</div><div class="getuigenis-content"><?php the_excerpt(); ?></div>
<!-- Add Link to single getuigenis -->
"><p>Lees Meer</p>
<hr><?php endwhile;
echo '</div>';
do_action( 'genesis_after_endwhile' );
endif;wp_reset_query();
}genesis();
July 8, 2016 at 3:34 am #189081Brad Dalton
ParticipantPlease paste your code in a Gihub Gist and link to it from here.
As it stands, your code is broken because its embedded incorrectly and therefore cannot be easily tested. Thanks.
July 12, 2016 at 9:02 am #189287Stefaan5
MemberFirst time doing that.
Here's the link:
Sorry for that later response. For some kind of reason I didn't get a response Email from Studiopress in my inbox.
Thanks for your quick reply though!
July 12, 2016 at 10:08 am #189293Brad Dalton
ParticipantWhy are you using custom fields?
<h2><?php the_title(); ?><span> - <?php the_field('adres'); ?></span></h2>
I assume you want to display the address inline with the title on both archives and single CPT pages?
Also, please link to the page so i can see the output.
I suggest you use the CPT code from the Executive Pro child theme rather than a plugin. Any reason you use the plugin for the CPT?
Also, better not to use ACF functions as they break if the plugin is deactivated. Use get_post_meta or genesis_get_custom_field.
July 12, 2016 at 10:47 am #189310Stefaan5
MemberThanks for the quick reply.
I am using the custom fields so I can add individual custom posts through the wp-CMS.
And the plug-ins are super easy. But if ACF breaks if deactivated, I should probably code them. I'll have a look at the Executive Pro child theme for that.
Thanks for leading me in the right direction.I didn't know there was a genesis_get_custom_field function though! Any idea where I can find a list of all the built in functions for genesis?
Also, I am developing the site on a local server, using MAMP. So, I won't be able to show you the actual page.
But do you see anything that could result in the 404 page? As I said, the pagination does show up. It just always leads to a 404 page.July 12, 2016 at 10:58 am #189314Brad Dalton
ParticipantI am using the custom fields so I can add individual custom posts through the wp-CMS.
Aren't you using them to add the address to the title?
Genesis itself is the best place to look for functions. You can do a search for them in the entire genesis folder.
I think you'll find the 404 will be fixed when you use the CPT code rather than a plugin and filter the entry title to add custom field.
Re-save your permalinks after adding the CPT code to functions.
No need for a new WP_Query.
You can use pre_get_posts to modify the CPT archive loop and use the single and archive cpt files to modify the default output on single CPT's and archives.
July 12, 2016 at 11:50 am #189324Stefaan5
MemberThank you for this.
I'll get to work and see if this solves it!
August 2, 2016 at 6:35 am #190642Stefaan5
MemberSorry it took so long to give an update on this post, I was on a summer holiday!
But anyway, the issue was resolved by following the given tips.
The main issue seemed to be created when I generated a new WP_Query.
Modifying the loop in the archive-cpt file + single cpt file and using the pre_get_posts to alter the number of posts worked perfectly.Another issue resolved! Thanks Brad!
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.