1

I made some Custom Post Types, filled them up with some posts, added the template tags to the templates.

The problem now is that whenever I click the 'Read More' button on a custom post type (the_permalink()), it doesn't show the singlepage. It shows the homepage.

I've created a single.php file and a single-smoelenboek.php file, it should go to 1 of those 2.

I've also flushed by clicking the 'Save' button in settings -> permalinks.

Permalinks are on Post Name right now, I them around a bit, but it didn't matter.

The Custom Post Type

    function smoelenboek() {
    $labels = array(
    'name'               => _x( 'Smoelenboek Sectie', 'post type general name', 'your-plugin-textdomain' ),
    'singular_name'      => _x( 'Smoelenboek Sectie', 'post type singular name', 'your-plugin-textdomain' ),
    'menu_name'          => _x( 'Smoelenboek Sectie', 'admin menu', 'your-plugin-textdomain' ),
    'name_admin_bar'     => _x( 'Smoelenboek Sectie', 'add new on admin bar', 'your-plugin-textdomain' ),
    'add_new'            => _x( 'Smoelenboek item toevoegen', 'content', 'your-plugin-textdomain' ),
    'add_new_item'       => __( 'Voeg een nieuwe Smoelenboek item toe', 'your-plugin-textdomain' ),
    'new_item'           => __( 'Nieuwe Smoelenboek item', 'your-plugin-textdomain' ),
    'edit_item'          => __( 'Bewerk Smoelenboek item', 'your-plugin-textdomain' ),
    'view_item'          => __( 'Bekijk Smoelenboek item', 'your-plugin-textdomain' ),
    'all_items'          => __( 'Alle Smoelenboek items', 'your-plugin-textdomain' ),
    'search_items'       => __( 'Zoek Smoelenboek items', 'your-plugin-textdomain' ),
    'parent_item_colon'  => __( 'Hoofd Smoelenboek items', 'your-plugin-textdomain' ),
    'not_found'          => __( 'Geen Smoelenboek items gevonden', 'your-plugin-textdomain' ),
    'not_found_in_trash' => __( 'Geen Smoelenboek items gevonden in prullenbak', 'your-plugin-textdomain' )
    );

    $args = array(
    'label' => __('smoelenboek'),
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => false,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'smoelenboek' ),
    'capability_type'    => 'post',
    'has_archive'        => false,
    'hierarchical'       => true,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'revisions','post-formats' )
    );

    register_post_type( 'smoelenboek', $args );
    }

add_action( 'admin_init', 'smoelenboek' );

The Section

<?php $options = get_option( 'custom_voorpagina_panel_smoelenboek' );  ?>
<section id="smoelenboek">
<div class="container persoon-wrapper">
<h1> <?php echo $options['smoelenboek-titel']; ?> </h1>
<h3> <?php echo $options['smoelenboek-sub-titel']; ?> </h3>

<?php
$loop = new WP_Query(
array(
'post_type' => 'smoelenboek', 
'posts_per_page' => 4
)
);
while($loop->have_posts()):
$loop->the_post();
$thumbnail_url = wp_get_attachment_url(get_post_thumbnail_id());

?>

<div class="persoon">
<?php 

$image = get_field('afbeelding');

if( !empty($image) ): 


// thumbnail
$size = 'products_thumb';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];

?>

<img src="<?php echo $thumb; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>">
<div class="wrapper">
<h3> <?php the_title(); ?> </h3>
<a href="<?php the_permalink() ?>"> <?php the_field('button_tekst') ?></a>
</div>
</div>
<?php
endif;
endwhile;
?>  
</div>   

<div class="meer-personen container">
<a href="/"> <?php echo $options['smoelenboek-bekijk-meer']; ?> </a>
</div>

</section>

Conclusion: Created custom post type, single page of custom post type not working. It would be nice if someone could help me with this.

EDIT: also single-smoelenboek.php is not working.
EDIT 2: /hello-world works. Picks up the single.php perfectly fine.

Thanks, Dan.

17
  • 1
    Please, add all the relevant code to the question itself. The question and its answer must be useful on its own without relying on external services, specially if the external services just display code. Imaging that the external sevice goes down: the question will be almost totally useless.
    – cybmeta
    Jul 25, 2016 at 10:08
  • Yeah I tried that, code would mess up.
    – Frisidan
    Jul 25, 2016 at 10:16
  • 1
    The permalinks should be /smoelenboek/*posts* Do you have any redirect rules active? Also on a side note where did you hook the function smoelenboek
    – bagpipper
    Jul 25, 2016 at 11:38
  • 1
    @bagpipper No redirects, and I hooked the function above the function: add_action( 'admin_init', 'smoelenboek' );
    – Frisidan
    Jul 25, 2016 at 11:46
  • 2
    Your hook is wrong. Use init. admin-init only fires on admin screens. Jul 25, 2016 at 11:48

1 Answer 1

2

The admin-init hook only fires on admin screens. The correct hook to use for registering post types is init.

So change:

add_action( 'admin_init', 'smoelenboek' );

... to ...

add_action( 'init', 'smoelenboek' );

... and flush your rewrite rules once (save permalink settings in admin) and all should be well.

1

Your Answer

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

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