WordPress.org

Ready to get started?Download WordPress

Forums

Can't get custom field values to work! (3 posts)

  1. mYrAn
    Member
    Posted 4 years ago #

    Hi! Iv'e downloaded this plugin. What im trying to achive here is to get a field value to set the class of my header, but it just wont work.. Im probably doing something really easy wrong, but im not to familiar with php.. Here's a bit of code, i think it'll explain what i want to do.
    <div id="header" class="<?php echo c2c_get_post_custom( $field ) ?>">
    What ive done this far is to create a custom field called "ommig" with the value "ommig", then put [custom_field field="ommig" /] in the editorbox, and the code above in the page.php. Please explain if you know what im doing wrong :c

  2. There's a few things that could be wrong with what you're doing. What template are you trying to modify? I'm presuming you are working on the single.php template file? If so, you can use c2c_get_current_custom() instead of c2c_get_post_custom() since the latter requires that you first explicitly provide a post ID, whereas the former will use the current post (assuming you are in the single.php or page.php template).

    Also, you are sending a variable, $field, to the function, but have you set that variable? If not, you should just send the name of your custom field, i.e. 'ommig'.

    Finally, you don't need to put the shortcode (the [custom_field field="ommig" /] bit) inside your post if your intent is only to set the class for that div. The shortcode will just insert the value of the custom field into the body of your post.

    So... ultimately you probably just want to replace the example code you provided above with:

    <div id="header" class="<?php echo c2c_get_current_custom('ommig'); ?>">

    Then for a post, create the custom field called "ommig" with a value (which it sound like you've done already).

    This particular set of code only makes sense and works properly if you are working in single.php.

    Hope that helps.

  3. syncbox
    Member
    Posted 4 years ago #

    @mYrAn

    Did c2c's answer help you? If it solved the issue, please mark your post resolved so the rest of us can take advantage of the solution, thanks!

    BTW, I LOVE this plugin. When I use other custom write page plugins, I almost always fall back on this plugin for display - either because the authors of the custom template or write pages don't have English documentation or tutorials out there for them are out of date.

    csc_get_custom is my FAVORITE plugin! Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic