I am trying to create my first wordpress theme. But I have run into som problems. When I click the link (the_permalink()) it leads back to the homepage. I get the right URL but the URL is showing the homepage, so I feel I am missing something.
So far I got a header.php, footer.php, sidebar.php, functions.php, style.css and index.php. The index file contains my loop.
I have also created a custom post type. And it is the custom post type I am looping in index.php.
What am I missing? Why does the permalink lead me to the homepage (loop page/index.php)? I have tried created single.php and single-customposttypeslug.php both empty so far. But that did'nt sovle my problem.
So what am I missing? I have been googling, searching SO and looked into the codex but I can't figure out what I am doing worng..
My permalinks looks like this websitename.com/index.php/property/test6/
The Loop:
<?php
/* START THE LOOP */
$loop = new WP_Query( array( 'post_type' => 'properties', 'posts_per_page' => 8 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post();
/* GET METADATA */
$city = get_post_meta( get_the_ID(), 'city_id', true );
$rentorsale = get_post_meta( get_the_ID(), 'rentorsale_id', true );
$price = get_post_meta( get_the_ID(), 'price_id', true );
$livingarea = get_post_meta( get_the_ID(), 'livingarea_id', true );
$bedrooms = get_post_meta( get_the_ID(), 'bedrooms_id', true );
$bathrooms = get_post_meta( get_the_ID(), 'bathrooms_id', true ); ?>
<a href="<?php the_permalink(); ?>">
<div class="col-md-3"> <!-- START BS COL-MD-3 -->
<div class="poststyle"> <!-- START POSTSTYLE -->
<div class="postheader"> <!-- START POSTHEADER -->
<h2><?php echo $city; ?></h2>
</div> <!-- END POSTHEADER -->
<div class="imgcontainer"> <!-- START IMGCONTAINER -->
<?php the_post_thumbnail(); ?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/img/1.jpg" alt="property" title="Real Estate"/>
<div class="rentorsale"> <!-- START RENTORSALE -->
<p><?php echo $rentorsale; ?></p>
</div> <!-- END RENTORSALE -->
<div class="price"> <!-- START PRICE -->
<p><?php echo $price; ?> <i class="fa fa-usd"></i></p>
</div> <!-- END PRICE -->
</div> <!-- END IMGCONTAINER -->
<table class="table"> <!-- START BS TABLE -->
<tr>
<td>Size</td>
<td><?php echo $livingarea; ?></td>
</tr>
<tr>
<td>Bedrooms</td>
<td><?php echo $bedrooms; ?></td>
</tr>
<tr>
<td>Bathrooms</td>
<td><?php echo $bathrooms; ?></td>
</tr>
</table> <!-- END BS TABLE -->
</div> <!-- END POSTSTYLE -->
</div> <!-- END BS COL-MD-3 -->
</a>
<?php endwhile; wp_reset_query();
?>
Register custom post type:
<?php
add_action( 'init', 'properties_post_type' );
function properties_post_type() {
$args = array(
'description' => __( 'Post type to manage properties', ' ' ), // string
'public' => true, // bool (default is FALSE)
'publicly_queryable' => true, // bool (defaults to 'public').
'exclude_from_search' => false, // bool (defaults to 'public')
'show_in_nav_menus' => false, // bool (defaults to 'public')
'show_ui' => true, // bool (defaults to 'public')
'show_in_menu' => true, // bool (defaults to 'show_ui')
'show_in_admin_bar' => true, // bool (defaults to 'show_in_menu')
'menu_position' => 6, // int (defaults to 25 - below comments)
'menu_icon' => null, // string (defaults to use the post icon)
'can_export' => true, // bool (defaults to TRUE)
'delete_with_user' => true, // bool (defaults to TRUE if the post type supports 'author')
'hierarchical' => false, // bool (defaults to FALSE)
'has_archive' => 'false', // bool|string (defaults to FALSE)
'query_var' => 'properties', // bool|string (defaults to TRUE - post type name)
'capability_type' => 'post', // string|array (defaults to 'post')
'map_meta_cap' => true, // bool (defaults to FALSE)
'rewrite' => array(
'slug' => 'property', // string (defaults to the post type name)
'with_front' => false, // bool (defaults to TRUE)
'pages' => true, // bool (defaults to TRUE)
'feeds' => true, // bool (defaults to the 'has_archive' argument)
'ep_mask' => EP_PERMALINK, // const (defaults to EP_PERMALINK)
),
'supports' => array(
'title',
'editor',
'excerpt',
'author',
'thumbnail',
'trackbacks',
'custom-fields',
'revisions',
'page-attributes',
'post-formats',
),
'labels' => array(
'name' => __( 'Properties', ' ' ),
'singular_name' => __( 'Property', ' ' ),
'menu_name' => __( 'Properties', ' ' ),
'name_admin_bar' => __( 'Properties', ' ' ),
'add_new' => __( 'Add New', ' ' ),
'add_new_item' => __( 'Add New Property', ' ' ),
'edit_item' => __( 'Edit Property', ' ' ),
'new_item' => __( 'New Property', ' ' ),
'view_item' => __( 'View Property', ' ' ),
'search_items' => __( 'Search Properties', ' ' ),
'not_found' => __( 'No properties found', ' ' ),
'not_found_in_trash' => __( 'No properties found in trash', ' ' ),
'all_items' => __( 'All properties', ' ' ),
'archive_title' => __( 'Properties', ' ' ),
)
);
/* Register the post type. */
register_post_type(
'properties',
$args // Arguments for post type.
);
}
?>
wp_reset_query
forwp_reset_postdata
, but that won't fix your issue