K
K
kostritsaalex2020-05-02 16:33:06
WordPress
kostritsaalex, 2020-05-02 16:33:06

Custom Post Type (PODs framework) – slug modification drive 404 / Not found?

Hello , I'm using the

PODs framework for WP.
Created several custom post types and linked them together.

There is a need to reflect this relationship in the link structure (slug).
Example: domain/custom-post1/custom-post2/post-title

In connection with this, I created a costume function of the following form:

<?php

function custom_post_slug ( $post_link, $post ) {

    /* Pulling the relation post slug */
    $quote_author = get_post_meta($post->ID, 'quote_author', true);
    $quote_author['post_name'];

    /* Condition for 'quote' post type */
    if ( 'quote' != $post->post_type || 'publish' != $post->post_status ) {
        return $post_link;
    }
    /* Modifying slug */
    $post_link = str_replace( '/' . $post->post_type . '/', '/' . $quote_author['post_name'] . '/' . $post->post_type . '/', $post_link );
    return $post_link;
}
add_filter( 'post_type_link', 'custom_post_slug', 10, 3 );

?>


The function itself works, as the link structure acquires the expected structure. The problem is that the post page gives an error:
404 / not found

What am I missing?
Maybe there are more correct ways to solve it through rewrite?

thanks for the help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nastya, 2020-05-02
@Chupizdik

here , but there, too, not without jambs ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question