Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What i'm trying to achieve:

Replace {$post_title} in a review plugin that displays the Post's Title with a Custom Field. The Custom Field will be called thumb with URL to an image.

What I have

Code to display custom field

Here is the code that I use on my customized WP page, it displays the image from the custom field 'thumb'

<?php
  $custom_fields = get_post_custom($post_id); //Current post id
  $my_custom_field = $custom_fields['thumb']; //key name
  foreach ( $my_custom_field as $key => $value )
  echo "<img src='" . $value . "'>";
?>

Code in the plugin that calls the post title

$return .= "<td class='myrp_primary_alt_col myrp_name'><a class='post_name' href='" . get_permalink($post_id) . "'>{$post_title}</a></td>";

I'm not sure how to code in PHP so that the custom field can be displayed instead of post title.

Appreciate your responses to this.

Thanks.

share|improve this question

closed as too localized by toscho Jan 2 at 23:18

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

So if I understand correctly, you are storing meta information for posts with meta_key "thumb", which you use somewhere in your website (theme or plugin or ..).

You would like to alter the output of a 3rd party plugin so it includes your meta, in the form of a thumbnail. Replacing {$post_title} with something of your own would to the trick but of course it'd be bad practice so you're looking for another solution.

I would think that any way around, it would be a bit of a hacky solution because you're dealing with output of another plugin. I'm not a Wordpress pro but I think the context in which this plugin outputs its content might be handy:

If the plugin's output is given in a place where you can simply override it, like in a list table, you might be able to do something like this:

add_filter('manage_upload_columns', 'my_callback');
function my_callback($columns) {
  // edit $columns, including something like 'my_column_override' => 'Hello'
}
add_action('manage_media_custom_column', 'my_column_overrider', 10, 2);
function my_column_overrider($colname, $post_id) {
  // spit out your own html
}

..or it might be in a meta box, in which case we might hack into it like so (not very sure, but see http://core.trac.wordpress.org/browser/tags/3.3.1/wp-admin/includes/template.php#L901):

$plugin_callback = $wp_meta_boxes[$page][$context][$priority][$id]['callback'];
$wp_meta_boxes[$page][$context][$priority][$id]['callback'] = 'my_callback';
function my_callback($post) {
  ob_start();
  call_user_func($plugin_callback, $post);
  $plugin_html = ob_get_clean();
  // spit out your own html
}
share|improve this answer
Thanks for your comment. A bit high level for me so to speak. Isn't it possible to use the original code (replacing it with {$post_title} ? – Sledge81 Feb 28 '12 at 14:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.