WordPress.org

Ready to get started?Download WordPress

Forums

Boilerplate
[resolved] Include custom fields on category page (6 posts)

  1. KS Web Designer
    Member
    Posted 8 months ago #

    So I am using a boilerplate wordpress theme, and I have a few custom fields on a custom post type. I'm drawing a blank while trying to get those custom fields to appear on my categories page.

    On the individual post pages I can simply use:

    print_custom_field('overrideJobDesc');

    However when I try the same trick in my categories.php page I get nothing. Can someone point me in the right direction?

    <?php get_header(); ?>
    
                <h1><?php
                    printf( __( 'Category Archives: %s', 'boilerplate' ), '' . single_cat_title( '', false ) . '' );
                ?></h1>
                <?php
                    $category_description = category_description();
                    if ( ! empty( $category_description ) )
                        echo '' . $category_description . '';
    
                /* Run the loop for the category page to output the posts.
                 * If you want to overload this in a child theme then include a file
                 * called loop-category.php and that will be used instead.
                 */
                get_template_part( 'loop', 'category' );
                ?>
                <?php print_custom_field('overrideJobDesc'); ?>
  2. Aaron T. Grogg
    Member
    Theme Author

    Posted 8 months ago #

    From my understanding of get_template_part, it returns the completed loop results, so you're not really still inside of it when you're you call print_custom_field, are you?

    Are you able to get anything from get_custom_field() or get_post_meta()?

    Atg

  3. KS Web Designer
    Member
    Posted 8 months ago #

    Good point. I gave it a go and still nothing...
    Adding get_custom_field('overrideJobDesc'); didn't show up anything and adding get_post_meta(); resulted in the below error message:

    Warning: Missing argument 1 for get_post_meta(), called in /path/to/wp-directory/wp-content/themes/theme/category.php on line 26 and defined in /path/to/wp-directory/wp-content/themes/theme/post.php on line 1792

  4. Aaron T. Grogg
    Member
    Theme Author

    Posted 8 months ago #

    Well, for one thing get_post_meta requires at least a $post_id parameter:
    http://codex.wordpress.org/Function_Reference/get_post_meta
    That should clear-up the error message.

    Also, you are aware that both get_custom_field and get_post_meta simply return values, not echo them, right? Just checking...

    But I still go back to the fact that I think you're asking for info outside of the loop, so it might not be available to you where you're asking for it... Maybe try a custom query?

  5. KS Web Designer
    Member
    Posted 8 months ago #

    Thanks, as you might be able to tell I was in a little over my head. I've done a little reading around The Loop and other things you mentioned. I think I've come up with a solution, although it's basically rewritten the category.php page.

    Thank you for your patience :)

  6. Aaron T. Grogg
    Member
    Theme Author

    Posted 8 months ago #

    Ok, as long as you got it working! :-)

Reply

You must log in to post.

About this Theme

About this Topic

Tags

No tags yet.