Quantcast
Channel: help – WordPress.org Forums
Viewing all articles
Browse latest Browse all 13924

Jason818 on "Need Help! -- Single Page Not working on Custom Post Type"

$
0
0

Hello I just got a new laptop and transferred a local site I was working on. When I relaucnhed it the single page and archive page no longer works for my custom post type.

When I click on a link it goes to my home page. I have read tips all day long and It only work when I have permalinks to default. I cannot use any custom permalinks. Please help.

Here is my Custom Post type:

// REGISTER CUTOM POST TYPE
function cl_create_post_type() {
	$labels = array(
	'name' => __( 'Events', 'cl' ),
	'singular_name' => __( 'Event', 'cl' ),
	'add_new' => __( 'New Event', 'cl' ),
	'add_new_item' => __( 'Add New event', 'cl' ),
	'edit_item' => __( 'Edit event', 'cl' ),
	'new_item' => __( 'New event', 'cl' ),
	'view_item' => __( 'View event', 'cl' ),
	'search_items' => __( 'Search events', 'cl' ),
	'not_found' => __( 'No Events Found', 'cl' ),
	'not_found_in_trash' => __( 'No Events found in trach', 'cl' ),
	);

//DEFINE WHATS NEEDED IN THE EDITOR
$args = array(
	'labels' => $labels,
	'public' => true,
	'show_ui' => true,
	'capability_type' => 'post',
	'hierarchical' => true,
	'has_archive' => true,
	'supports' => array(
		'title',
		'editor',
		'thumbnail',
		'excerpt'),//END OF ARRAY
	'rewrite' => array(
		'slug' => 'events',
		'pages' => true,
		'with_front' => FALSE ),
	'taxonomies' => array(
		'post_tag',
		'category')//END OF ARRAY
);// END OF ARGS ARRAY

register_post_type( 'event' , $args );

}// END OF CL_CREATE_POST_TYPE

add_action( 'init', 'cl_create_post_type' );

function my_rewrite_flush() {
    flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'my_rewrite_flush' );

//REGISTER TAXONOMY
register_taxonomy( 'events' ,
	array(
		'hierarchical' => true,
		'rewrite' => true,
		)
);

add_action( 'add_meta_boxes' , 'cl_create_event_meta_box' );

//CREATE CUSTOM FILEDS IN EVENTS EDITOR
function cl_create_event_meta_box() {
	add_meta_box(
		'cl_create_event_meta_box', 'Event Options', 'cl_create_event_metabox', 'event', 'normal', 'high' );
}//END OF EVENT MANAGER ADD META FUNCTION

function cl_create_event_metabox($post ) {
	global $post;
	$custom = get_post_custom( $post->ID );
	$location = $custom[ "location" ] [0];
	$address = $custom[ "address" ] [0];
?>

	<style type="text/css">
	<?php include_once( 'event-manager.css' ) ?>
	</style>

	<div class="event_metabox_extras">

		<div>
			<label>Location:</label>
			<input name="location" value="<?php echo $location ?>"/>
		</div>
			<div>
			<label>Address:</label>
			<input name="address" value="<?php echo $address ?>"/>
		</div>

	</div><!-- /event_metabox_extras -->
	<?php
}

add_action( 'save_post', 'event_metabox_save_extras');

function event_metabox_save_extras($post ) {

	global $post;

	update_post_meta( $post->ID, "location", $_POST[ "location"] );
	update_post_meta( $post->ID, 'address', $_POST[ 'address'] );

}

Here is my HTML/PHP in my page-events.php:

<?php
					$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
					$cltheme_event_param = array (
						'post_type' => 'event'

					);//END OF ARRAY

					$the_query= new WP_Query( $cltheme_event_param);
					if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
				?>
				<?php
					//GET CUSTOM FIELDS
					$custom = get_post_custom( $post->ID );
					$location = $custom[ "location" ] [0];
					$address = $custom[ "address" ] [0];
				?>

					<li>
						<article>
							<?php the_post_thumbnail( 'event-sm-thumb' ); ?>
							<img src="<?php print IMAGES ?>/news-divider.png" alt="content divider" />
							<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php the_title(); ?></a></h2>
							<p class="date-post">Posted: <time datetime="<?php the_time( 'Y-m-d' ); ?>" pubdate="pubdate"><?php the_time( 'Y-m-d' ); ?></time></p>
							<img src="<?php print IMAGES ?>/news-divider.png" alt="content divider" />
							<p class="ebox1">
								<span class="event">Location:</span> <?=$location?>
							</p>
							<p class="ebox1">
								<span class="event">Address:</span> <?=$address?>
							</p>
							<?php the_content('Read More...'); ?>
							<div class="spacer"></div>
							<!-- TAXONOMY -->
							<div class="tax">
								<div class="alignleft">
									<p>Category: <?php the_category( ', ' ); ?></p>
								</div>
								<?php if( get_the_tags() ); { ?>
								<div class="alignright">
									<p><?php the_tags(); ?></p>
								<div>
								<?php } ?>
							</div><!-- /END OF TAX -->
						</article>
					</li>

				<?php
					endwhile; endif;

					wp_reset_postdata();
				?>

			</section>

				<?php
			//pagination
				echo '<nav class="pagination" >';
				echo  '<ul>';
				echo  '<li>'.get_next_posts_link('Previous', $the_query->max_num_pages).'</li>'; //Older Link using max_num_pages
				echo  '<li>'.get_previous_posts_link('Next', $the_query->max_num_pages).'</li>'; //Newer Link using max_num_pages
				echo '</ul>';
				echo "</nav>";
			?>

Here is the HTML/PHP in my single-events.php :

<?php  if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
				<?php
					//GET CUSTOM FIELDS
					$custom = get_post_custom( $post->ID );
					$location = $custom[ "location" ] [0];
					$address = $custom[ "address" ] [0];
				?>

						<article>
							<?php the_post_thumbnail( 'event-sm-thumb' ); ?>
							<img src="<?php print IMAGES ?>/news-divider.png" alt="content divider" />
							<h2><?php the_title(); ?></h2>
							<p class="date-post">Posted: <time datetime="<?php the_time( 'Y-m-d' ); ?>" pubdate="pubdate"><?php the_time( 'Y-m-d' ); ?></time></p>
							<img src="<?php print IMAGES ?>/news-divider.png" alt="content divider" />
							<p class="ebox1">
								<span class="event">Location:</span> <?=$location?>
							</p>
							<p class="ebox1">
								<span class="event">Address:</span> <?=$address?>
							</p>
							<?php the_content(); ?>
							<div class="spacer"></div>
							<!-- TAXONOMY -->
							<div class="tax">
								<div class="alignleft">
									<p>Category: <?php the_category( ', ' ); ?>
								</div>
								<?php if( get_the_tags() ); { ?>
								<div class="alignright">
									<p><?php the_tags(); ?></p>
								<div>
								<?php } ?>
							</div><!-- /END OF TAX -->
						</article>

				<!-- THICK GREY BOTTOM BORDER -->
				<div class="box-bottom"></div>
				<?php
				//pagination
					echo '<nav class="pagination" >';
					echo  '<ul>';
					echo  '<li>';
					echo  next_post_link('<strong>%link</strong>');
					echo  '</li>';
					echo  '<li>';
					echo previous_post_link('<strong>%link</strong>');
					echo  '</li>';
					echo '</ul>';
					echo "</nav>";
				?>
				<?php endwhile; else: ?>
				<p><?php _e( 'The Post you are looking for could not be found.' ); ?></p>
				<?php endif; ?>

I would really appreciate any help..


Viewing all articles
Browse latest Browse all 13924

Trending Articles