Listing Posts with code not working!
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).
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.
maybe something like this (not tested)
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.
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)
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 🙁
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
I’m not using the category in the query as my test site only have one…
re-check your category ID as well
How did you get the custom post field for those posts?
Also could you maybe contact me on MSN ? my msn is: email@example.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.
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.
sorry, i don’t have msn
follow the full code I posted and you should get it working
I still can’t get this to work. Hoping someone else could also help me.
- The topic ‘Listing Posts with code not working!’ is closed to new replies.