Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • Ok, just checked in Chrome for JS errors and everything looks clear.

    http://pastebin.com/3te8z76g

    I’ve given you two examples, this is just one implementation, I thought it would be best to start small in order to figure out where I’m going wrong. Your plugin is used all over this site, so right now just about everything is broken. πŸ™

    I’ll check the admin box now.

    Is this what you need? http://pastebin.com/iFf4YQ80

    Hey Scribu, I installed 1.2-alpha3 as you suggested, but still no luck with the connection boxes in the admin area. The previous problem of incorrect connections on the front end is still persisting.

    Thanks.

    Well, the connections show up in the front-end, but they are the wrong ones and are the same ones for all posts of the same type. I haven’t had the chance to update my function calls yet though.

    Just tried making new connections in the admin boxes–no luck. The spinner shows up when I search, but it can’t find the custom post types I am trying to connect, and won’t connect anything.

    Thanks again for your time, I really appreciate your help with this.

    All right, so far so good. I followed your instructions and now the wp_p2p table has been populated with the names of the connections that I specified. The last piece of the puzzle: the connections are not showing up in the post-editing screens. To double checked, I cross-referenced a pair of connected posts according to their IDs from the table and the connection makes sense. However, neither of their editing screens show the connection.

    Thanks for the speedy reply!

    I guess the problem is, I have a LOT of connections (in the 100s) that all disappeared after the upgrade and the p2p_type column is empty. In order to fill the column using SQL directly, I would have to cross-reference the id of every post/page that used to be connected to another…is there any way to reinitialize the plugin so that it registers the connections and uses the ‘name’ parameter I specified? (Oh yes, I forgot to mention that I did try explicitly naming the connection as well.)

    Thanks!

    Hi Scribu,

    So far I’ve followed the instructions you’ve given here, but I am hesitant to fill in the empty p2p_type column with my own hash. I’ve updated WordPress and the plugin to the lastest versions, tried setting p2p_storage to 3 and also explicitly naming each connection. However, all my connections are gone from both the front end and the backend. Is there anything else I can try? Also, it seems like p2p_storage doesn’t stay set to 3, it goes back to 4 when I check, and when I click “Update Connections,” it says “0 connections updated.”

    Thanks!

    Thread Starter reneelung

    (@reneelung)

    Hey Scribu,

    So I ended up doing just that. The reason why it was getting a little hairy was 1) I have a massive data set and 2) paging already makes me nervous because I’m working with a codebase that isn’t my own.

    Anyways, in case people have the same issue, I ended up making two separate queries (ie, two new WP_Query objects) and then combining the result set from both. This is because I needed a seamless continuation of the results (which are displayed as a grid), with paging.

    $posts_with_pics_query = "select p.id from wp_posts as p, wp_postmeta as m
    where m.post_id = p.id
    and m.meta_key = '_thumbnail_id'
    and p.post_type = 'athletes'";
    
    $posts_with_pics_ids = $wpdb->get_col($posts_with_pics_query);
    
            $listing = new WP_Query(array_merge(
                       array(
                            'post_type' => 'athletes',
                            'connected_to' => $connected_post_id,
                            'paged' => $wp_query->query_vars['paged'],
                            'posts_per_page' => 16,
                            'post__in' => $posts_with_pics_ids
                             ), $meta));
    
            $listing_no_pics = new WP_Query(array_merge(
                                array(
                            'post_type' => 'athletes',
                            'connected_to' => $connected_post_id,
                            'paged' => $wp_query->query_vars['paged'] - $listing->max_num_pages,
                            'posts_per_page' => 16,
                            'post__not_in' => $posts_with_pics_ids
                            ), $meta));

    So now there are two separate sets of posts, one taken from all the posts that have featured images, and those without. In order to merge them, we append the results of the second query to the first taking care to adjust post_count, found_posts and max_num_pages for paging etc:

    //I'm showing 16 posts on each page, so if the first query's results //run out, I want to fill in the difference with posts from the second //set. However, if we set $listing->post_count to 16, then it'll keep //looping 16 times regardless of whether or not there are any posts //left in either set.
    $listing->post_count = min(16, $listing->post_count + $listing_no_pics->post_count);
    //For any given page, merge the results of both queries
            $listing->posts = array_merge($listing->posts, $listing_no_pics->posts);
    //This is here to make sure the pagination function works properly
            $listing->found_posts = $listing->found_posts + $listing_no_pics->found_posts;
            $listing->max_num_pages = ceil($listing->found_posts / 16);

    Thanks for the direction, and for getting back to me so quickly!

    Thread Starter reneelung

    (@reneelung)

    Thanks for getting back to me so quickly!

    I tried your snippet, but it didn’t seem to work. I inserted it into my functions.php file, logged out and logged back in just be sure, but I’m still getting all the athletes.

    I also tried the query_vars hook, but that didn’t seem to work either.

    function add_p2p_qv ($public_query_vars) {
        $public_query_vars[] = 'connected_to';
        return $public_query_vars;
    }
    
    add_action( 'query_vars', 'add_p2p_qv' );

    People seem to think a parse_request filter is also needed, but I’m not familiar enough with hooks and filters to tell.

    Any suggestions?

Viewing 10 replies - 1 through 10 (of 10 total)