• I encounter a situation where posts-to-posts 1.1.4 is outputting an error message that didn’t show up with version 1.1.3.

    The message is:
    Warning: Can't determine direction in .../plugins/posts-to-posts/core/query-post.php on line 60

    Generally the plugin is still working fine. This error occurs only at one place in the theme : a location where the p2p $connected query actually *cannot* return anything. In the previous version there was simply no output, in 1.1.4 I see the error message.

    More details:

    I have three content types: let’s call them posts, custom-type-A (fruits), custom-type-B (vegetables).

    p2p is setup to handle reciprocal connections between posts-fruits and posts-vegetables (not between fruits and vegetables). So that’s two possible relations.

    The single.php template contains queries for both relations. That’s because WP will use it as default template for posts, fruits, and vegetables.

    Now, if we are visiting the page of some fruit – maybe “banana” – the $connected query that is asking for related posts is working OK, but the other query, asking for related vegetables, won’t return anything: that’s normal, since a relation fruit-vegetable isn’t implemented. It was just giving no result with 1.1.3, and it’s now showing the error message in 1.1.4.

    The simple solution for me, of course, is to create more specific pages (single-fruit.php, single-vegetable.php, etc). It’s certainly better not to run unnecessary queries anyway.

    Regarding the code I’m using for the queries, I simply followed the examples provided here: https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage

    https://www.ads-software.com/extend/plugins/posts-to-posts/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author scribu

    (@scribu)

    This error occurs only at one place in the theme : a location where the p2p $connected query actually *cannot* return anything. In the previous version there was simply no output, in 1.1.4 I see the error message.

    Yes, that was intentional.

    Thread Starter Manuel Schmalstieg

    (@targz-1)

    Ok, then I guess the issue is resolved ??

    So is there a solution to this?
    I am getting the same error and only in one place as well.
    The plugin works great in a bunch of my template files except for one of them.
    Any solutions?

    Thread Starter Manuel Schmalstieg

    (@targz-1)

    @snails07 : in my exemple above, you would need to modify the single.php template file, since the way we call the p2p query will be different, depending on the post type.

    You would need to change content of the main loop in single.php, to something like this:

    if ( 'fruit' == get_post_type() ) {
    	include( TEMPLATEPATH . '/inc/single-fruit.php' );
    }
    elseif ( 'vegetable' == get_post_type() ) {
    	include( TEMPLATEPATH . '/inc/single-vegetable.php' );
    }
    else {
    	include( TEMPLATEPATH . '/inc/single-article.php' );
    }

    The code above will call specific includes, single-fruit.php etc, which you have to create and name as you find practical, depending on your post types. Those sub-templates are the place where you will insert the appropriate p2p query.

    I hope this helps your troubleshooting.

    Hello, just installed, thank you for this plugin,

    Im trying to set a connection between (well known example ;)) actor (custom post type) and movie (custom post type). But I need to set this connection on a specific page which is none of this custom types (neither actor or movie).

    What should be proper approach for this? Shall I call a Loop for this specific movie?

    p2p_type( ‘actor_to_movie’ )->connect( $actor_id, $movie_id, array(
    ‘date’ => current_time(‘mysql’)
    ) );
    Warning: Can’t determine direction in /wp-content/plugins/posts-to-posts/core/type.php on line 84

    Best regards, plugin is very helpful.

    Thread Starter Manuel Schmalstieg

    (@targz-1)

    @ Bart Ploom:

    Indeed, I think you will need to create a custom loop that calls the desired custom types. As per my experience, you need to create this loop with the query_posts method (if you use WP_Query, p2p won’t work properly).

    See https://codex.www.ads-software.com/Function_Reference/query_posts

    Here is an example, perhaps something like this will work for you:

    global $wp_query;
     $args = array_merge( $wp_query->query, array(
     'post_type' => array('actor', 'movie'),
     ) );
    query_posts( $args );
    Plugin Author scribu

    (@scribu)

    Creating connections is a completely different process. Making a loop using query_posts(), WP_Query or get_posts() makes absolutely no difference.

    p2p_type( ‘actor_to_movie’ )->connect( $actor_id, $movie_id, array(
    ‘date’ => current_time(‘mysql’)
    ) );

    Warning: Can’t determine direction in /wp-content/plugins/posts-to-posts/core/type.php on line 84

    Are you absolutely sure that $actor_id is actually an ‘actor’ post and $movie_id is a ‘movie’ post?

    Thread Starter Manuel Schmalstieg

    (@targz-1)

    Making a loop using query_posts(), WP_Query or get_posts() makes absolutely no difference.

    Indeed, my mistake. In my early testing, I missed some crucial bits of information:

    • the need to specify 'suppress_filters' => false with get_posts, as explained here.
    • the need to replace get_queried_object_id() with $post->ID on templates other than single.php (or to use the each_connected() syntax described in Looping-The-Loop)

    Thanks a lot Scribu for expanding those help pages on GitHub!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Posts 2 Posts] Update to 1.1.4 causes "Can't determine direction" error’ is closed to new replies.