last day (14 days later) » 

2:40 PM
3
Q: Not sure where to put this code for my custom post type?

HarryI have a custom post type (called 'discount') that I am trying to display in the twentythirteen theme. I created a custom page file called discount-page.php to create my own template for this post type. I'm not sure where I need to place the wp_query code, however. Here's what the default page.ph...

 
You'll need to put it outside of the main loop, either somewhere before or after. So before this: <?php /* The loop */ ?> or after this: <?php endwhile; ?>.
Also, place your endif; from this line <?php endif; wp_reset_postdata(); ?> with endwhile; and remove the last line in your custom loop, which is this: <?php endwhile; ?>.
 
Awesome, thank you. So this is what I ended up with as my code: pastebin.com/VNnukriV but It seems to have broken my page. Any idea what I'm doing wrong?
 
Your pastebin code is not correct, give me a couple minutes to sort through it and I'll post again.
Are you looking to have the main loop in addition to the custom loop, or just the custom loop only?
 
Okay so I changed up the code to this pastebin.com/npCnTSVj and while it no longer breaks my page, it doesn't show any of the content? Not sure why
 
Try this: pastebin.com/NsQNr29H. You are opening a loop, and then opening another loop, and there are not content tags for the first loop. The pastebin above should show your CPT loop, then your main loop. You shouldn't open a loop inside of another loop.
If it works, I'll post it as an answer so you can accept it.
 
2:40 PM
I tried it but no content showed. Here's what I see: thriftyus.hlwebsites.com/grid-test (please ignore the horrible everything, this page is just for testing)
 
Hmm, that is odd. You should have content showing. Can you copy the entire page template code into a pastebin so I can see it?
 
Sure
Thanks again for helping me out
I really appreciate it
 
Yep, no prob. Slow morning at work anyway.
 
haha, same for me
alright here is what i have pastebin.com/wZy6XrLA
 
Give me a couple minutes, just got called to a quick meeting.
 
2:44 PM
sure no problem
 
Sorry man, this is going to take about 30 inutes...I'll reply soon.
 
no problem at all. take your time
 
3:07 PM
 
Hey stewart, I tried it but it does not show any content
this is all i see
 
What is the file called?
if you rename the file to archive-discount.php and try this code out pastebin.com/GPj39NiD and see what happens
 
Renaming it to archive-discount.php would be an archive page for the post type, not accessible through the page he wants a custom loop on.
I don't see why you aren't getting any content, the code from your last pastebin looks correct to me.
Are you sure there are posts in the post type?
 
hmm
yes, I have 3 posts in the post type
the file is discount-page.php
 
If you want to send me FTP and WP admin details I'll take a look. You can send it privately here: andy-warren.net/#contact.
 
3:23 PM
sure, will do
thanks guys
 

last day (14 days later) »