Support » Plugins » post_meta_cache and 1.5.1

Viewing 2 replies - 1 through 2 (of 2 total)
  • ok i found where this is defined (wp-includes/template-functions-post.php). However, it appears to be assigned quite differently than in 4.2.2, and I can’t quite see how to hack the definition so that its populated with info for ALL posts, rather than just the current one.

    What I have working in 4.2.2 is the following — a site with a main (feature) story and two miniblogs in colums on the side. One of them includes preview images, defined via a custom tag called ‘preview_image’ which is set to the URL of a preview image, if one exists. If so, then the image is displayed in the miniblog. If not, the excerpt is instead. The miniblogs are generated with kitten’s ‘show category posts’ plugin.

    The code I have in 4.2.2 is (for the miniblog with the preview images):

    <?php if ($scp_posts) : foreach ($scp_posts as $post) : start_wp(); ?>

    <!– for each post, check to see if it has a defined preview image (URL in the ‘previewimage’ tag –>
    <?php $thepostid = $post->ID; $vals = $post_meta_cache[$thepostid][‘previewimage’]; ?>

    <!– if so, show the preview images and link them to the story –>

    <?php if ($vals) : foreach ($vals as $val) : ?>
    <h3>” rel=”bookmark” title=”Permanent Link: <?php the_title(); ?>”><?php the_title(); ?></h3>
    ” title=”Permanent Link: <?php the_title(); ?>”><img class=”previewimage” src=”<?php echo $val ?>” alt=”<?php the_title(); ?>”/>
    <?php endforeach; ?>
    <?php else: ?>

    <!– otherwise show the excerpt instead –>

    <h3>” rel=”bookmark” title=”Permanent Link: <?php the_title(); ?>”><?php the_title(); ?></h3><?php the_excerpt(); ?>
    <?php endif; ?>

    <?php endforeach; ?>

    …the only way this works is with a hacked wp-blog-headers.php, where the query which generates $meta_list is modifed as below, to populate the list with the metadata for ALL posts, rather than the ones displayed in the main loop. the reason for this is that the show_category_posts is looping over a bunch of posts which AREN’T in the main loop, and hence the test to see if they have a particular tag defined won’t otherwise work, as the matadata array won’t be posulated with their information — follow?!

    The hack in wp-blog-header.php is this:

    // Get post-meta info
    // db hack 20050301: removed selction WHERE post_id IN($post_id_list)
    // in the following query to return ALL metadata for ALL posts, not just the ones in the
    // main part of the page — so that the show_category_list indexes can make use of them

    if ( $meta_list = $wpdb->get_results(“
    SELECT post_id,meta_key,meta_value
    FROM $tablepostmeta
    ORDER BY post_id,meta_key
    “, ARRAY_A) ) {

    Now that’s all fine in 4.2.2, and you can see the whole thing working at — the ‘creative’ column is generated by this hackand the above loop.

    The problem is how to replicate this behavious in 1.5.1. The code in template-functions-post.php seems optimised so that it doesn’t have access to what in 4.2.2 is called $tablepostmeta in the same way, and i’m damned if i can see who to tweak the code to return all the data i need for this to work. alternatively, i can’t work ou a different loop in index.php to achieve the same reult in 1.5.1 without hacking this.

    I hope that’s sufficient explanation — if not, please let me know. Again, a quick look at the site should show what I’m trying to achieve — remember the key here is that i use SCP to display the images which URLs are stored in a custom tag (‘preview_image’) if that tag is defined, or the exceprt if not, in the column laballed ‘creative’ on the site.

    All help appreciated!


    – Darrell

    ok solved. this quirk has aactually been implemented PROPERLY in 1.5 — its possible to call something like:

    <?php $array= get_post_custom($thepostid); $vals=$array[‘previewimage’]; ?>

    and have this return correct values, it seems, even if the post in question isn’t one touched in the main loop.


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘post_meta_cache and 1.5.1’ is closed to new replies.