WordPress.org

Ready to get started?Download WordPress

Forums

Listing Posts with code not working! (10 posts)

  1. faeronsayn
    Member
    Posted 2 years ago #

    So I am trying to list posts that have a parentID embedded in them. This parentID is a custom field in the post. I just want to list posts that have the same parentID as the current post so it displays in that post.

    This is what I have so far for the code, i've placed this in single.php (my post template).

    http://pastebin.com/SziB1RF7

    Now I am not good at all with php so I know there are a lot of mistakes in this code. I simply want you guys to help me fix this code so I can use it. Currently when I try to use it, it doesn't work since it shows nothing. Without the IF statement, it shows the posts, but they are displayed everywhere and are not specific to the parent post. Please someone help fix this.

  2. brasofilo
    Member
    Posted 2 years ago #

    maybe something like this (not tested)
    http://pastebin.com/gwPSP19n

  3. faeronsayn
    Member
    Posted 2 years ago #

    Hello brasofilo, not sure whats wrong but I have put the code into the template but I am not getting any output. Could this be because of the Custom Field, I am not currently sure. But there is no output.

  4. brasofilo
    Member
    Posted 2 years ago #

    sorry,
    in my code, the condition should be
    if ($thePostID == $parentID2)

    being the $thePostID the variable that you set in your original code

    (I've tested and it works)

  5. faeronsayn
    Member
    Posted 2 years ago #

    Sorry for bothering you but I've added that in and it still does not show anything.

    Here is the pastebin link: http://pastebin.com/YvmCYZNr

    Thats the new code, that I am currently using which is not working for me :(

  6. brasofilo
    Member
    Posted 2 years ago #

    It would be better to see the full code...
    but at a first sight the $thePostID = $post->ID; should be inside the loop

    here's how I have it working in Twentyeleven single.php
    http://pastebin.com/4P3pDBbP

    I'm not using the category in the query as my test site only have one...
    re-check your category ID as well

  7. faeronsayn
    Member
    Posted 2 years ago #

    How did you get the custom post field for those posts?

    Also could you maybe contact me on MSN ? my msn is: faeronsayn@hotmail.com

    This is the code that works, but displays all posts in the category, and does not make use of the post parent ID checking through IF statement.

    http://pastebin.com/FHJdGLX0

    Any other code I try no posts show up. So please if you could possibly add me on MSN, I am sure it would be much easier, since i'll be able to explain this to you in greater detail.

  8. brasofilo
    Member
    Posted 2 years ago #

    sorry, i don't have msn

    follow the full code I posted and you should get it working

  9. faeronsayn
    Member
    Posted 1 year ago #

    I still can't get this to work. Hoping someone else could also help me.

  10. faeronsayn
    Member
    Posted 1 year ago #

    Just wondering.

    The code that was provided above, how can it be adapted to look through custom post type posts ?

Topic Closed

This topic has been closed to new replies.

About this Topic