WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Custom Content Type Manager] How to display custom fields in archive? (2 posts)

  1. grasnal
    Member
    Posted 2 years ago #

    I need to display values of my custom fields in category archive view. I have custom content type working as a simple image gallery. This type stores only title and image uploaded via "Image field". I'am able to display it in single post view using this code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    TIA!

  2. fireproofsocks
    Member
    Posted 2 years ago #

    Looks like the moderator shut you down for that code sample... can you paste it in the http://wordpress.pastebin.com/ ?

    Category archive view... which template file is that? category.php?

    The CCTM theme files get_custom_field() and print_custom_field() are scoped to a specific post because you have to be in the context of a given post before you can talk about getting or printing its custom fields.

    I haven't seen your code yet, but this really sounds like a job for my other plugin: http://wordpress.org/extend/plugins/summarize-posts/

    That plugin was built for exactly this type of flexibility. You can do some very flexible searches and the results returned include the custom fields as part of the records returned, all with a single database query.

    For example, in your theme file, you could do something like this:

    <?php
       $Q = new GetPostsQuery();
       $Q->post_type = 'your_custom_content_type';
       $Q->taxonomy = 'category';
       $Q->taxonomy_term = 'My Favorites';
       $results = $Q->get_posts();
       foreach ($results as $r) {
          print $r->post_title;
          $image_id = $r->my_image_field;
          print wp_get_attachment_image_src( $image_id, 'full', true);
       }
    ?>

    Note that the custom image field here would be returned in its raw form (i.e. as the integer key), so you have to use one of WP's image functions, e.g. wp_get_attachment_image_src in order to get the image. This is because Summarize Posts doesn't apply the output filters used by the CCTM... but I'm working to integrate the 2 in a future release.

    See http://code.google.com/p/wordpress-summarize-posts/wiki/get_posts for some more examples and explanations.

Topic Closed

This topic has been closed to new replies.

About this Topic