WordPress.org

Ready to get started?Download WordPress

Forums

display custom post types.. please help! (9 posts)

  1. robertingram
    Member
    Posted 2 years ago #

    I am sure this is really simple but I just cant work it out so if someone can help me would be amazingly grateful! Pretty new to this. Thanks.

    website: http://gugo.co.uk

    I have created a post type called 'comedy' which has taxonomies of 'comedian', 'venue' and 'price' using the custom post type UI plugin. I have then created a single post template for this called single-comedy.php to display the comedy custom posts. To test that the comedy post type was diverting to the single-comedy.php template I put this in there: <p>This is the template single-comedy.php</p>. You can see this here so it is definitely using that template http://gugo.co.uk/comedy/comedy-custom-post-test/.

    What I am trying to do is display the 'comedian', 'venue' and 'price' meta info in the post. I have included <?php the_meta(); ?> in the single-comedy.php template directly below
    <?php get_template_part( 'content', 'single' ); ?>template
    but it is not displaying the custom meta.

    I tested on a normal post putting in the standard custom fields section on a post and it shows correctly. I edited single.php and entered <?php the_meta(); ?> and it shows the custom meta info on the post. You can see this here http://gugo.co.uk/27/09/2011/normal-post-test/

    So what I need to know is am I going about this the right way by creating a new post template called single-comedy.php and if so what code do i need to enter to display the custom fields that are generated by the custom post type UI plugin.

    Thank you in advance for any help..

  2. SpankMarvin
    Member
    Posted 2 years ago #

    Is the custom data really a taxonomy? It sounds like it'll be more likely using some form of get_post_custom.

    Try adding this to your template to see what the output, if any, is:

    $custom = get_post_custom($post->ID);
    print_r($custom);

    BTW I'm assuming this is within a regular loop where the post is $post...

  3. robertingram
    Member
    Posted 2 years ago #

    Hi SpankMarvin, thanks for replying.

    I entered this into the post template:

    <?php $custom = get_post_custom($post->ID);
    print_r($custom); ?>

    you can see the output here: http://gugo.co.uk/comedy/second-comedy-test/

    Sorry, really not to sure what you mean by - assuming this is within a regular loop where the post is $post...
    It is within the loop as far as I know.

  4. SpankMarvin
    Member
    Posted 2 years ago #

    Hmm, doesn't look like there's any other custom data using that function, then. I'm sorry, not sure what else to suggest...

  5. robertingram
    Member
    Posted 2 years ago #

    Ah shucks, thanks for trying though Spank. This has been bugging me for days.

    The custom post type UI plugin is so simple to setup but i just cannot work out how to display the custom fields in a post. It is really easy to display the standard custom fields that wordpress provides that is explained here http://codex.wordpress.org/Custom_Fields but I just cannot display the info from the custom post type UI plugin.

    Anyone..? Someone must be using this plugin and displaying the info on their posts. Help out a noob would ya..

  6. SpankMarvin
    Member
    Posted 2 years ago #

    Not sure about how the plugin asks you to define the custom fields, but I guess it'd be worth trying:

    $venue = get_post_meta($post->ID, "venue", true);

    And seeing whether that spits out anything useful?

  7. robertingram
    Member
    Posted 2 years ago #

    no output from that I'm afraid mate.

    I find lots of articles that tell you really well how to create custom post types but no one really goes into detail on how to display the fields in a post. eg/
    http://thinkvitamin.com/code/create-your-first-wordpress-custom-post-type/
    http://www.wpbeginner.com/wp-tutorials/how-to-use-custom-post-types/

    I reckon a well written post on the subject would get a lot of love..

  8. SpankMarvin
    Member
    Posted 2 years ago #

    Well, the conventional way OUGHT to be to use the get_post_custom() function. This works by saying something like $custom = get_post_custom($post->ID); and then calling, say, $venue = $custom['venue'][0]; to retrieve a field with the name attribute of "venue".

    However, unless I'm missing something, the plugin you are using must be storing these extra fields some other way...

  9. robertingram
    Member
    Posted 2 years ago #

    gona get a friend to have a look tomorrow hopefully. If I can come up with an answer will let you know.
    Thanks for your help Spank, is much appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic