Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Help show custom fields on wp-print WordPress

  • SOLVED

Hello I am trying to show my posts custom fields on the printable page that the WP Print plugin (http://wordpress.org/extend/plugins/wp-print/) creates.

In the Authors forum it explains how to do it , however I think this was for an older version of wordpress. (http://forums.lesterchan.net/index.php?topic=1377.0)

I added this to the print-posts.php but it does not show the custom field as it does on my single.php:

<?php $postsireurl = get_post_meta($post->ID, 'sire', true); if ($postsireurl) { ?><?php echo $postsireurl; ?><?php } else { ?><?php } ?>


I think I need to add a bit of code to the wp-print.php ?


If someone could tell me what snippets of code to add to what files I would be very appreciative.

Thanks

Answers (2)

2011-11-15

Christianto answers:

Hi,

Did you do it inside the loop or outside the loop?
The forum advise you to use get_the_id() instead of just $post->ID


Christianto comments:

This is example your code with the post id grab using get_the_ID function instead from $post object ($post->ID)

<?php $current_postid = get_the_ID(); $postsireurl = get_post_meta($current_postid, 'sire', true); if ($postsireurl) { ?><?php echo $postsireurl; ?><?php } else { ?><?php } ?>


Ross Gosling comments:

Thank you this works!!

2011-11-15

Julio Potier answers:

Hello can you share the page ? The one which you paste this code.

Thank you


Ross Gosling comments:

Hi Julio, this is my print-posts.php:

<?php

/*

+----------------------------------------------------------------+

| |

| WordPress 2.7 Plugin: WP-Print 2.50 |

| Copyright (c) 2008 Lester "GaMerZ" Chan |

| |

| File Written By: |

| - Lester "GaMerZ" Chan |

| - http://lesterchan.net |

| |

| File Information: |

| - Printer Friendly Post/Page Template |

| - wp-content/plugins/wp-print/print-posts.php |

| |

+----------------------------------------------------------------+

*/

?>



<?php global $text_direction; ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head>

<title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>

<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<meta name="Robots" content="noindex, nofollow" />

<?php if(@file_exists(TEMPLATEPATH.'/print-css.css')): ?>

<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/print-css.css" type="text/css" media="screen, print" />

<?php else: ?>

<link rel="stylesheet" href="<?php echo plugins_url('wp-print/print-css.css'); ?>" type="text/css" media="screen, print" />

<?php endif; ?>

<?php if('rtl' == $text_direction): ?>

<?php if(@file_exists(TEMPLATEPATH.'/print-css-rtl.css')): ?>

<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/print-css-rtl.css" type="text/css" media="screen, print" />

<?php else: ?>

<link rel="stylesheet" href="<?php echo plugins_url('wp-print/print-css-rtl.css'); ?>" type="text/css" media="screen, print" />

<?php endif; ?>

<?php endif; ?>

</head>

<body>

<p style="text-align: center;"><strong><?php bloginfo('name'); ?><br /><span dir="ltr"><?php bloginfo('url')?></span></strong></p>

<div class="Center">

<div id="Outline">

<?php if (have_posts()): ?>

<?php while (have_posts()): the_post(); ?>

<p id="BlogTitle"><?php the_title();?><?php $postsireurl = get_post_meta($post->ID, 'sire', true); if ($postsireurl) { ?>, <?php echo $postsireurl; ?> x <?php } else { ?><?php } ?><?php $postgrandsire1url = get_post_meta($post->ID, 'grandsire1', true); if ($postgrandsire1url) { ?><?php echo $postgrandsire1url; ?><?php } else { ?><?php } ?></p>

<p id="BlogDate"><?php print_categories('', ''); ?></p>

<div id="BlogContent"><?php print_content(); ?></div>

<?php endwhile; ?>

<hr class="Divider" style="text-align: center;" />

<?php if(print_can('comments')): ?>

<?php comments_template(); ?>

<?php endif; ?>

<p><?php _e('Article printed from', 'wp-print'); ?> <?php bloginfo('name'); ?>: <strong dir="ltr"><?php bloginfo('url'); ?></strong></p>

<p><?php _e('URL to article', 'wp-print'); ?>: <strong dir="ltr"><?php the_permalink(); ?></strong></p>

<?php if(print_can('links')): ?>

<p><?php print_links(); ?></p>

<?php endif; ?>

<p style="text-align: <?php echo ('rtl' == $text_direction) ? 'left' : 'right'; ?>;" id="print-link"><?php _e('Click', 'wp-print'); ?> <a href="#Print" onclick="window.print(); return false;" title="<?php _e('Click here to print.', 'wp-print'); ?>"><?php _e('here', 'wp-print'); ?></a> <?php _e('to print.', 'wp-print'); ?></p>

<?php else: ?>

<p><?php _e('No posts matched your criteria.', 'wp-print'); ?></p>

<?php endif; ?>

</div>

</div>

<p style="text-align: center;"><?php echo stripslashes($print_options['disclaimer']); ?></p>

</body>

</html>