0

(My issue is not that described in 'post_type_link' filter not working. In that instance Rizwan was attempting to use post_type_link to filter posts, which are instead handled by post_link.)

In my case I'm trying to use post_type_link on a custom post type created by the Liquid Messages plugin. The post type is 'gc-sermons' and my code is as follows:

function lqd_message_link( $url, $post ) {
  if ( get_post_type( $post ) == 'gc-sermons' && isset( $wp_query->query_vars['messages-app-view'] ) ) {
    return add_query_arg( $_GET, $url );
    }
  return $url;
  }
add_filter( 'post_type_link', 'lqd_message_link', 10, 2 );

If you go to a sermon series page like the below:

https://liquidchurch.com/sermon-series/divine-direction/messages-app-view/

And then mouse over one of the messages you see the link URL is:

https://liquidchurch.com/message/step-by-step

Whereas I'm looking for it to be:

https://liquidchurch.com/message/step-by-step/messages-app-view/

Any ideas?

Note: The CPT (gc-sermons) is set during its registration with ep_mask as EP_ALL.

4

1 Answer 1

0

Milo provided the answer in the comments above. I'm recording for posterity sake. :)

I was using add_query_arg and should instead have used return $url, so the code above should have looked like:

function lqd_message_link( $url, $post ) {
   global $wp_query;
   if ( get_post_type( $post ) == 'gc-sermons' && isset( $wp_query->query_vars['messages-app-view'] ) ) {
   return $url . 'messages-app-view/';
}
   return $url;
}
add_filter( 'post_type_link', 'lqd_message_link', 10, 2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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