WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
Issue grabbing post connected to future post (3 posts)

  1. 10sexyapples
    Member
    Posted 1 year ago #

    On my home template I'm grabbing the most recent published post of a custom post type called "tsa_announcement".

    Just below this I'm querying the most recent "future" post of the same custom post type "tsa_announcement" ... but, only because I have connected a news "post" to the future "tsa_announcement" and would like to show that connected news post's title and permalink.

    Currently I am attempting to do this with the following code as my second new WP_Query on the template ... the first query has been closed out with wp_reset_query~

    <?php
    	global $post;
    	$my_query = null;
    	$my_query = new WP_Query( array(
    		'post_type' => 'tsa_announcement',
    		'post_status' => 'future',
    		'tsa_announcement_type' => 'exhibition-opening'
    		)); ?>
    
    		<?php while ($my_query->have_posts()) : $my_query->the_post();?>
    
    		<?php
    		    // Find connected pages (for all posts)
    		    p2p_type( 'news_and_announcements' )->each_connected( $my_query );
    		?>
    		<?php
    		    // Display connected pages
    		    p2p_list_posts( $post->connected, 'before_list=&after_list=&before_item= &after_item=' );
    		?>			
    
    		<?php endwhile; ?>
    		<?php wp_reset_query(); ?>

    ... but, I am receiving SQL errors ...

    should this even work with a future post?

    Thanks as always Scribu!

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    What SQL errors?

  3. 10sexyapples
    Member
    Posted 1 year ago #

    Sorry ... I accidentally responded to this in the wrong place ...

    I only kept one of them ... and, I think I may have even changed the post_status to published to test when I got this error ... but, here is an example

    WordPress database error: [Incorrect usage/placement of 'SQL_CALC_FOUND_ROWS']
    
    SELECT wp_posts.*, wp_p2p.* FROM wp_posts INNER JOIN wp_p2p LEFT JOIN wp_p2pmeta AS p2pm_order ON ( wp_p2p.p2p_id = p2pm_order.p2p_id AND p2pm_order.meta_key = '_order_from' ) WHERE 1=1 AND wp_posts.post_type IN ('post') AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 43 AND wp_posts.post_status = 'private') AND (wp_p2p.p2p_type = 'news_and_announcements' AND wp_posts.ID = wp_p2p.p2p_to AND wp_p2p.p2p_from IN (SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.ID IN (3723) AND wp_posts.post_type IN ('tsa_announcement') AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 43 AND wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 1)) ORDER BY p2pm_order.meta_value+0 ASC, wp_posts.post_date DESC

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic