0

I have created a custom post type 'property' on my WordPress site with a taxonomy of 'property-category'. I have a php snippet to display the next and previous posts in the CPT of the current term eg. the next Property in the same category.

previous_post_link( '%link', '%title', TRUE, ' ', 'property-category' );

However, I need to place this in a module in a page builder, so I thought I could make a shortcode out of it. But that’s where I’m getting stuck.

I’ve tried to create my own shortcode by adding this to the functions file,

function fivehats_previous_post() {
previous_post_link( '%link', '%title', TRUE, ' ', 'property-category' );
}
add_shortcode( 'fh_prev', 'fivehats_previous_post' );

I placed [fh_prev] in the module on the page template for single-property but I seem to be missing a step, as the shortcode is not out-putting anything.

Does anybody have any suggestions as why that's not working, or even a different solution to get the nav links to properties within the current category to work?

-1

Have you tried to echo get_previous_post_link as this is what is called when you set function previous_post_link.

function fivehats_previous_post() {
// You need to echo it out for it to display in the page
echo get_previous_post_link( '%link', '%title', TRUE, ' ', 'property-category' );
}
add_shortcode( 'fh_prev', 'fivehats_previous_post' );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.