WordPress.org

Forums

Inject custom field into header (4 posts)

  1. Sean Turtle
    Member
    Posted 4 years ago #

    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.

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

    <?php get_post_meta($post->ID, 'custom_css', true); ?>
    the echo is missing in that line.

  3. Sean Turtle
    Member
    Posted 4 years ago #

    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.

  4. alchymyth
    Forum Moderator
    Posted 4 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic