admin管理员组

文章数量:1122846

I'm working on a function for bibliographic citations with get_post_meta.

A bibliographic citation contains several elements, (author, date, title, etc.), each of these elements is a get_post_meta value. The bibliographic citation function orders these elements according to bibliographic standards (e.g. APA).

Example

Function for elements the citation

function editorial() {
    global $wp_query;
    $post = $wp_query->post;
    $editorial = get_post_meta($post->ID, 'acervo_editorial', true);
    if (!empty($editorial)) {
        echo $editorial.', ';
    }
}

function pubdate() {
    global $wp_query;
    $post = $wp_query->post;
    $pubdate = get_post_meta($post->ID, 'acervo_pubdate', true);
    if (!empty($pubdate )) {
        echo $pubdate.', ';
    }
}

function for citation

function article_citation() {
    global $wpdb;
    global $wp_query; 

    echo '<p>';
    editorial();
    pubdate();
    echo '</p>';
}

If I put the echo get_post_meta directly in the template it works

$pubdate = get_post_meta($post->ID, 'acervo_pubdate', true);
        if (!empty($pubdate )) {
            echo $pubdate.', ';
}

but if I put the citation function some elements work and others don't. Something is wrong but I don't know what it is.

article_citation();

本文标签: wp queryfunctions with getpostmeta