Skip to content

Instantly share code, notes, and snippets.

@surefirewebserv
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save surefirewebserv/4987734d263072362ad9 to your computer and use it in GitHub Desktop.
Save surefirewebserv/4987734d263072362ad9 to your computer and use it in GitHub Desktop.
Add this to functions.php
<?php //Don't Copy This Line
//Add to single product page.
add_action( 'woocommerce_single_product_summary', 'return_policy', 999 );
function return_policy() {
// Find connected pages
$connected = new WP_Query( array(
'connected_type' => 'posts_to_pages', // Use same name as you used in the previous function.
'connected_items' => get_queried_object(),
'nopaging' => true,
) );
// Display connected pages
// This is just a standard WordPress loop
if ( $connected->have_posts() ) :
?>
<div class="product_meta">
<h2>List of whatever posts</h2>
<?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
<span><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>,
<?php endwhile; ?>
</div>
<?php
// Prevent weirdness
wp_reset_postdata();
endif;
}
<?php
// Don't copy the php tag above.
function prefix_unique_connection_types_name() {
p2p_register_connection_type( array(
'name' => 'posts_to_pages', //Give it a name that you can reference
'from' => 'post', // This can be the slug name of your CPT as well
'to' => 'page' // This can be the slug name of your CPT as well
) );
}
add_action( 'p2p_init', 'prefix_unique_connection_types_name' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment