ThemeShaper Forums » Thematic

[closed]

Adding Custom Fields to post - Please help

(9 posts)
  • Started 13 years ago by McEnroe
  • Latest reply from helgatheviking
  • This topic is not resolved

Tags:

  1. McEnroe
    Member

    Hi all!

    I been searching for hours and hours and can't seem to find anything for a php ignorant like me.

    I need to display some custom fields on posts. These fields are named TDOMF Form #6 Custom Field #_1 --- TDOMF Form #6 Custom Field #_2 --- TDOMF Form #6 Custom Field #_3 --- TDOMF Form #6 Custom Field #_4 and so on... I've searched on the wordpress codex and I also saw some other topics in this forum but nothing seems to suit to my needs. Can somebody help me out on this?

    I guess I must add these custom fields on the content-extensions.php file but I can't manage how to do it. I guess it should be done in this piece of code, right?

    // The Single Post
    if (function_exists('childtheme_override_single_post')) {
    function thematic_single_post() {
    childtheme_override_single_post();
    }
    } else {
    function thematic_single_post() {

    thematic_abovepost(); ?>

    <div id="post-<?php the_ID();
    echo '" ';
    if (!(THEMATIC_COMPATIBLE_POST_CLASS)) {
    post_class();
    echo '>';
    } else {
    echo 'class="';
    thematic_post_class();
    echo '">';
    }
    thematic_postheader(); ?>
    <div class="entry-content">
    <?php thematic_content(); ?>

    <?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    </div><!-- .entry-content -->
    <?php thematic_postfooter(); ?>
    </div><!-- #post -->
    <?php

    thematic_belowpost();
    }
    } // end single_post

    Hope someone can help me out!

    Thank you very much,

    Posted 13 years ago #
  2. I am using this plugin to do some magic with my posts, not sure if it's what you're looking for:
    http://wordpress.org/extend/plugins/get-custom-field-values/

    In my case I use it to check and see if an entry has an author of Guest-Crosspost. If so, instead of the usual by-line, it says Guest-Crosspost | By: [Outside Author Field] | Soruce: [Link]

    Posted 13 years ago #
  3. McEnroe
    Member

    Oh, thank you so much. I will check it out now, will let you know. :)

    Posted 13 years ago #
  4. McEnroe
    Member

    The plug-in is great but I need to add the same custom fields to all the posts. Any help?

    Posted 13 years ago #
  5. So that the custom fields have the same value in every post? Wouldn't they be different every time? (The keys are the same, but the data is different.) I guess I'm not 100% on what you're trying to do, sorry.

    In my case I'm using function childtheme_override_postmeta_authorlink()

    the operating lines of code using the plugin are:
    c2c_get_custom('Outside Author');
    c2c_get_custom('Source');

    ...which spits out the values of those two keys. I'm sure there's a way to set the value in the function as well, but someone who knows their way around PHP would have to chime in.

    As a side note, you just helped me realize how I could achieve something I was wanting to do, so thanks back at you. (I want to allow someone to insert content into a sliding div at the bottom of every post.)

    Posted 13 years ago #
  6. McEnroe
    Member

    hehe... No problem Solomon, you are welcome :)

    Many thank's for your help.

    The custom fields are always the same, the data is different everytime. Basically what I'm doing is kind of a contest system using TDO Mini Forms plug in where anyone can upload some obligatory information and upload a picture so after an admin can accept or decline this information. All the submissions are stored as different posts and, as I said, these posts can be accepted or not. Everything works perfect, the only problem I have is that all the custom fields people fill in when sending a submission remain on posts as custom fields and the information contained on these custom fields it's not displayed by default on posts. What I need then is to tell Thematic to write these custom fields on every post, the ID of the fields is always the same, the data stored is always different (as this is the information users sends over when filling the form). This is why I need to know how to include custom fields on thematic posts.

    Hope you understand me, my english is terrible!

    Many thank's for your help.

    Posted 13 years ago #
  7. @McEnroe
    i haven't used TDO miniforms and dont completely understand your required outcome...
    but maybe this may help or put you on the right track.

    if i wanted to grab a custom field value and display within a single post, i'd do the following... pop it in your child theme functions.php

    // The Single Post
    function childtheme_override_single_post() {
    
    global $post;
    thematic_abovepost(); ?>
    
    <div id="post-<?php the_ID();
    echo '" ';
    if (!(THEMATIC_COMPATIBLE_POST_CLASS)) {
    post_class();
    echo '>';
    } else {
    echo 'class="';
    thematic_post_class();
    echo '">';
    }
    thematic_postheader(); ?>
    <div class="entry-content">
    <?php thematic_content(); ?>
    
    <?php $contestform = get_post_meta($post->ID, 'INSERT ID HERE', true);
    if ($contestform  == ''){ ?> <p> no contest here <?php } else { ?>
    <div class="contest-form">
    <?php echo $contestform; ?>
    </div>
    <?php } ?>  
    
    <?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    </div><!-- .entry-content -->
    <?php thematic_postfooter(); ?>
    </div><!-- #post -->
    <?php
    
    thematic_belowpost();
    
    } // end single_post

    within the above code, the part specific to grabbing the custom field is...

    <?php $contestform = get_post_meta($post->ID, 'INSERT ID HERE', true);
    if ($contestform  == ''){ ?> <p> no contest here <?php } else { ?>
    <div class="contest-form">
    <?php echo $contestform; ?>
    </div>
    <?php } ?>

    be sure to replace 'INSERT ID HERE' with the ID that corresponds with your custom field.

    hope this helps

    also, anyone reading this...
    i have had to add

    global $post;

    to my single post override for the custom field to work. i haven't had to do such in the past (but i tend not too use custom fields much).
    see this thread
    http://wordpress.org/support/topic/what-happened-to-post-gtid-emergency-help

    Posted 13 years ago #
  8. McEnroe
    Member

    Jonny, thank you so much! you saved me! it's working now :)

    Thank's!

    Posted 13 years ago #
  9. glad you got it solved. don't forget that you can read about WP functions like get_post_meta at the wordpress codex AND don't forget to mark the thread as solved.

    related to custom fields, i've almost completely replaced them w/ custom metaboxes. Check out WP-Alchemy. really powerful, metabox class.

    http://farinspace.com/wpalchemy-metabox/

    Posted 13 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.