Support » Plugins » Shwing posts by post_parent

  • I’m writing a plugin that assigns posts to particular pages (see genesis here

    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)
  • 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');

    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">';
    echo '</select></div></fieldset>';
    add_action('simple_edit_form', 'p2p_parentSelect');
    add_action('edit_form_advanced', 'p2p_parentSelect');

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

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

    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!

    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.