• I’m writing a plugin that assigns posts to particular pages (see genesis here https://www.ads-software.com/support/topic/46002).

    In my page.php template, I need two loops… The first shows the content of the page itself (the default behaviour) the second should show all posts for which post_parent is set to the current page_id…

    I’ve gotten a filter to achieve the second loop, but it borks the first one…

    Is get_posts the answer? query_posts()?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter cailean

    (@cailean)

    Here’s the filter I’m using…


    function p2p_query($where) {
    global $post_id, $wpdb;
    $where = " AND post_parent=$post_id";
    return $where;
    }
    add_filter('posts_where', 'p2p_query');

    Thread Starter cailean

    (@cailean)

    okay, ignore the code snippet above… I see the error of my ways!

    I am 99% there I just have one little issue – the most recent post is not being shown!

    Here is all the relevant plugin code:

    function p2p_parentSelect() {
    global $post_ID, $wpdb;
    $post_parent = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID = $post_ID ");

    echo '<fieldset id="postparent" rel="'.$post_parent.' - '.$post_ID.'">';
    echo '<legend>Assign to Page</legend> ';
    echo '<div><select name="parent_id">';
    parent_dropdown($post_parent);
    echo '</select></div></fieldset>';
    }
    add_action('simple_edit_form', 'p2p_parentSelect');
    add_action('edit_form_advanced', 'p2p_parentSelect');

    function p2p_query($where) {
    if(is_page())
    {
    $where = " AND post_parent=".$_GET['page_id'];
    }

    return $where;
    }
    function p2p_func(){
    add_filter('posts_where', 'p2p_query', 11);
    query_posts('');
    }

    the first loop in the page runs normally and then p2p_func() is called immediately before the second loop… works except most recent post is always missing!
    `

    Thread Starter cailean

    (@cailean)

    any help here, folks?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shwing posts by post_parent’ is closed to new replies.