-
Jericho
Hi there,
I’ve created a Portfolio custom post type (CPT) for my clients. On each client’s page, I want to display the next client at the bottom of the content. The order should follow the default publish date order.
Here’s what I’ve set up:
- In Elements, I created a Block with Element Type: Hook and Hook Name: after_content.
- Inside the editor, I added a Query Loop.
- For the Title and Featured Image, I set the Dynamic Tags source to Current Post.
- Query Loop settings:
- Post Type: Portfolios
- Posts Per Page: 1
- Exclude Posts: Current Post
- Display Rules: Location → Portfolio > All Portfolios
- Exclude: Front Page
The issue I’m facing is that the “next post” is not following the publish date order. It only shows two posts that keep looping, even though I have five portfolio posts in total.
Could you please let me know what might be wrong with my Query Loop setup or how I can get it to follow the correct post order?
Thanks so much for your help!
Best regards,
Jericho -
Alvind
Hi Jericho,
I don’t think you need to use the Query block for your setup.
You can keep your current element layout — just assign a dynamic tag directly to each element (the next link, title, and featured image).
For each of them, set the Source to Next post.
You can keep your existing display rules as they are.
-
Jericho
Oh, I hadn’t thought about this simple setup! Is it possible to loop when I reach the last post? Right now, when I get to the last post, no next post appears. Could it loop back to the earliest posts?
-
Alvind
With the current setup, unfortunately there’s no clean way to loop back to the first post when the current post is the last one.
However, there’s a workaround if you prefer. You can create another element with the exact same content as your existing one. This time, set the source to Specific Post and select the first post in your portfolio post type. Don’t set any display rules as we’ll handle that through a filter.
To write that filter, I need to know what defines the “last post” in your case. Is it based on menu order, or is it the most recently created portfolio? I’ll need that detail to write the correct display rule parameters.
- You must be logged in to reply to this topic.