Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've looked everywhere for a solution, but have yet to find one. Here is the situation. I've created a custom content type using the plugin Custom Content Type Manager and now have need to use these custom post types within pages that I've created in WP.

So I created a page called "Photos" and use a template php file to configure the layout / styles of the page. The plugin generated a sample template for me in order to get the custom fields that I've put in. It looks something like this:

get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    <h1><?php the_title(); ?></h1>
        <?php the_content(); ?>
        <?php the_author(); ?>

        <h2>Custom Fields</h2>  
        <strong>Image:</strong> <?php list($src, $w, $h) = get_custom_field('image:to_image_array');?>

        <img src="<?php print $src; ?>" height="<?php print $h; ?>" width="<?php print $w ?>" /><br />

<?php endwhile; // end of the loop. ?>

The Problem:

When I use "the_content();" and the other php methods, they pull the content from the page called "Photos", and not the content from the custom content type created with this plugin.

Is there something I can override / rewrite so that the_content(); from the custom content type shows up instead of the pages' content? Is there a better way I should be doing this other than creating WP pages and using custom templates? I am fairly new to this whole WP programming business..

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

The loop in your code is automatically going to pull data from the current page ID (i.e. Photos). You have to define the query for which data you're looking for. Be sure to replace photo with whatever the slug is for your post type.

See http://codex.wordpress.org/Class_Reference/WP_Query for other arguments you can use in addition to post_type.

<?php

$query = new WP_Query( array( 'post_type' => 'photo' ) );

if ( $query->have_posts() ) :

    while ( $query->have_posts() ) : $query->the_post(); ?>

             <?php the_title(); ?>

    <?php endwhile;

endif;

?>
share|improve this answer
add comment

I think what is happening here is that WP is noticing that your URL ends with "photos" and so it is structuring a query based on that. You don't want that. You need to set up your own query. This thread should give you an idea of how to structure your query.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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