• Hi

    I’m using the latest post from a certain category as a home page. I’d like to load a custom field (in this case, a css file) so that the post displays correctly.

    Here’s my code:

    <?php
    $css_query = new WP_Query();
    $css_query->query('category_name=mag_post&showposts=1');
    while ($css_query->have_posts()) : $css_query->the_post(); ?>
    <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'template_url' ); ?>/css/<?php get_post_meta($post->ID, 'custom_css', true); ?>" />
    <?php echo get_post_meta($post->ID, 'preview', true); ?>
    <?php endwhile; ?>

    But it isn’t returning anything. The custom field is definitely there.

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php get_post_meta($post->ID, 'custom_css', true); ?>
    the echo is missing in that line.

    Thread Starter Sean Turtle

    (@turts)

    Sorry, that code wasn’t even correct. This is the code in place:

    <?php
    $css_query = new WP_Query();
    $css_query->query('category_name=mag_post&showposts=1');
    while ($css_query->have_posts()) : $css_query->the_post(); ?>
    <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'template_url' ); ?>/css/<?php echo get_post_meta($post->ID, 'custom_css', true); ?>" />
    <?php endwhile; ?>

    But still nothing.

    is the category name mag_post with an underline?
    (this is supposed to use the category slug)

    http://codex.wordpress.org/Function_Reference/WP_Query#Category_Parameters

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Inject custom field into header’ is closed to new replies.