• On a post in WP, I have 3 custom fields say for example, with corresponding name and value.

    1. Africa – 10 Staff
    2. Australia – 20 Staff
    3. Asia – 30 Staff

    This will appear on post as-is. The post will have 3 tags namely Africa, Australia and Asia.

    Now, when I clicked on tag Asia, it will query the value only for Asia. Same goes when I view the page tagged as Africa, it will display value for Africa.

    I am doing this to avoid duplicate content for tag pages. Also to serve tag page as summary info.

    To sum it up. I created a tag.php and wanted to display this info for every tag pages.

    “In Asia we have approximately 30 Staff blah blah…”

    I managed to pull out just one with the following code

    In <?php single_tag_title(); ?> we have approximately
    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'asia', true);
    ?> blah blah.

    Need your help…
    Calling Nate once more…

Viewing 1 replies (of 1 total)
  • Thread Starter bongkph

    (@bongkph)

    All of the post in this web site will have those 3 tags.

    To make things even complicated, I dont know if it is possible to call different sets of custom field depending on category. Say for example…

    If category is 1 display this---
    In <?php single_tag_title(); ?> we have approximately
    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'asia', true);
    ?> blah blah.
    (Same sentence is displayed for tag africa and australia)
    
    If category is 2 display this---
    There are approximately
    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'asia', true);
    ?>possitioned across all <?php single_tag_title(); ?>
    (Same sentence is displayed for tag africa and australia)

    Thanks again for any help.

Viewing 1 replies (of 1 total)

The topic ‘Custom field global query’ is closed to new replies.