Viewing 7 replies - 1 through 7 (of 7 total)
  • Awesome plugin, but I’m having similar issues with Yoast’s WordPress SEO plugin. When Related is active, it wipes out all the Title, Keyword, and Meta info for every page/post, and replaces it with info from the last page saved. Really sucks, because this is a really cool plugin, and I really would like to use it.

    Thread Starter John Huebner

    (@hube2)

    You can see the explanation of why this plugin is causing the problem in the thread I posted in the seoaiop support. http://wordpress.org/support/topic/plugin-all-in-one-seo-pack-data-disappears-on-pagepost-edit?replies=5#post-3138931

    Has to do with altering the global post id.

    I rewrote the function that displays the related meta field on the post page. the important bit is after the query, rather that use the_post(), which overwrites the global post id I just loop through the results returned by the query.

    // Creates the output on the post screen
    public function displayMetaBox() {

    global $post;
    $post_id = $post->ID;

    // Get related posts if existing
    $related = get_post_meta($post_id, ‘related_posts’, true);

    if (!empty($related)) {
    echo ‘<div id=”related-posts”>’;
    foreach($related as $r) {
    $p = get_post($r);
    ?>
    <div class=”related-post” id=”related-post-<?php echo $r; ?>”>
    <input type=”hidden” name=”related-posts[]” value=”<?php echo $r; ?>”>
    <span class=”related-post-title”><?php echo $p->post_title; ?> (<?php echo ucfirst(get_post_type($p->ID)); ?>)</span>
    Delete
    </div>
    <?php
    } // end foreach post
    echo ‘</div>’;
    } // end if !empty

    $query = array(
    ‘nopaging’ => true,
    ‘post__not_in’ => array($post_id),
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => -1,
    ‘post_type’ => ‘any’,
    ‘orderby’ => ‘title’,
    ‘order’ => ‘ASC’
    );

    $p = new WP_Query($query);

    $count = count($p->posts);
    if ($count > 0) {
    ?>
    <p>
    <select id=”related-posts-select” name=”related-posts-select”>
    <option value=”0″>Select</option>
    <?php
    foreach ($p->posts as $thePost) {
    ?>
    <option value=”<?php
    echo $thePost->ID; ?>”><?php echo
    $thePost->post_title.’ (‘.ucfirst(get_post_type($thePost->ID)).’)’; ?></option>
    <?php
    }
    ?>
    </select>
    </p>
    <?php
    } // end if count
    wp_reset_query();
    wp_reset_postdata();
    }

    Thanks much Hube2. I appreciate the help!

    There is a little bug in this code (you can’t add related post on a post with none related post).
    You must put out the div “related-posts” of the brace.

    if (!empty($related)) {
    echo ‘<div id=”related-posts”>’;

    echo ‘</div>’;
    }

    =>

    echo ‘<div id=”related-posts”>’;
    if (!empty($related)) {

    }
    echo ‘</div>’;

    Thanks. I discovered that this plugin was the cause of a lot of headaches with another plugin due to it changing the global $post. Can this be incorporated a future release of this plugin as I would consider it a bug.

    (It hasn’t been updated in a while–will it be maintained?)

    Thanks.

    hey guys – I’m a novice and I’m having trouble understanding how to edit the code posted by Hube2 with the fix posted by photoscope – can someone help me out?! Pretty please? 😀

    Never mind! For anyone else…

    ‘// Creates the output on the post screen
    public function displayMetaBox() {

    global $post;
    $post_id = $post->ID;

    // Get related posts if existing
    $related = get_post_meta($post_id, ‘related_posts’, true);

    echo ‘<div id=”related-posts”>’;
    if (!empty($related)) {
    foreach($related as $r) {
    $p = get_post($r);
    ?>
    <div class=”related-post” id=”related-post-<?php echo $r; ?>”>
    <input type=”hidden” name=”related-posts[]” value=”<?php echo $r; ?>”>
    <span class=”related-post-title”><?php echo $p->post_title; ?> (<?php echo ucfirst(get_post_type($p->ID)); ?>)</span>
    Delete
    </div>
    <?php
    } // end foreach post

    } // end if !empty
    echo ‘</div>’;
    $query = array(
    ‘nopaging’ => true,
    ‘post__not_in’ => array($post_id),
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => -1,
    ‘post_type’ => ‘any’,
    ‘orderby’ => ‘title’,
    ‘order’ => ‘ASC’
    );

    $p = new WP_Query($query);

    $count = count($p->posts);
    if ($count > 0) {
    ?>
    <p>
    <select id=”related-posts-select” name=”related-posts-select”>
    <option value=”0″>Select</option>
    <?php
    foreach ($p->posts as $thePost) {
    ?>
    <option value=”<?php
    echo $thePost->ID; ?>”><?php echo
    $thePost->post_title.’ (‘.ucfirst(get_post_type($thePost->ID)).’)’; ?></option>
    <?php
    }
    ?>
    </select>
    </p>
    <?php
    } // end if count
    wp_reset_query();
    wp_reset_postdata();
    }’

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Related] Conflict with SEO All In One Pack’ is closed to new replies.