Support » Plugin: Custom Content Type Manager » Include fields from custom type on the home page

  • I have a custom type called Events with a category called Forthcoming Events.

    I’d like to create a slider for forthcoming events, something like

    <ul id="forthcomingEventsSlider">
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    	<h1><?php the_title(); ?></h1>
    		<img src="<?php print_custom_field('event_image'); ?>" />
    		<?php print_custom_field('event_content'); ?>
    <?php endwhile; // end of the loop. ?>

    I’m not sure how to ‘load up’ the Events from the home page and limit them to just events within the Forthcoming Events category.

    Any advice would be appreciated, thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor fireproofsocks


    I’ll say right off the bat that I loathe the have_posts() function — it’s WordPress’ little myopic and unpredictable view into the database which has very few options and a long list of caveats, so in a word, my best advice here is to avoid using it like the plague.

    What I recommend is using my other plugin, Summarize Posts — this will be merged into the Custom Content Type Manager plugin in an upcoming version because it’s so useful:

    What I’d do is set up a dedicated page for the homepage (e.g. use your theme’s home.php file), and on that page, you can effectively cross-link to list posts that appear somewhere else, e.g. to summarize your “Events” posts.

    $Q = new GetPostsQuery();
    $Q->post_type = 'events';
    $Events = $Q->get_posts();
    foreach ($Events as $e) {
       print $e->post_title;
       print $e->event_content;
       // ...

    Alternatively, you can use a simple shortcode to paste into that page’s content, and the effect will be comparable to the above.

    See for more documentation on the functions and filters available to you.

    Thanks very much for your help, I’ll have a look at this.

    Plugin Contributor fireproofsocks


    Hope it helps… the documentation for Summarize Posts is pretty rough (sorry), but it’ll all get revamped as I merge it with the CCTM plugin. I’ve used Summarize Posts on almost every recent WP site, and I’ve got an updated version to release of that as well.

    This did help, thanks. I just have one issue.

    Using the Custom Content Type Manager I have created an Events type.

    Using the following code in home_page.php

    $Q = new GetPostsQuery();
    $args = array();
    $args['post_type'] = 'events';
    $forthcoming_events = $Q->get_posts($args);

    <?php echo $fe->event_image;?> is being returned as a number.

    <?php print_custom_field('event_image'); ?> in events_single.php correctly returns it as a url.

    <?php print_custom_field('event_image'); ?> on the home page gives The event_image field is not defined as a custom field.

    How do I either use print_custom_field in home_page.php or translate the number (corresponding to a media(?)) into a URL?

    Any help is appreciated, thanks.

    Plugin Contributor fireproofsocks


    Glad this helped. I’ve gotten so many emails about this one… any media or relation field stores a foreign key to the image or post or page. It’s the post_id of the foreign thing being linked to. It achieves data normalization. But you’re not after the integer, you’re after what it represents.

    Have a look at this page in the wiki: — it attempts to explain this in more detail.

    Specifically you want to tie in the integer with one of WP’s functions, e.g. wp_get_attachment_image():

    foreach( $forthcoming_events as $r) {
       print wp_get_attachment_image($r->event_image, 'full');

    Once I integrate Summarize Posts with the CCTM, I can implement the defined output filters on the fields, but now since they are separate, you have to run the filters manually.

    I’ll have a look at this.

    Thanks, you’ve been really helpful.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Include fields from custom type on the home page’ is closed to new replies.