• Resolved dgirona

    (@dgirona)


    This function not work for my custom post types “empresas”:

    Permalink Manager can automatically update the custom permalink after post or term is saved/updated

    After sending new custom post type from de form Link structure is not maintained

    My perma structure is : empresas/%categorias_empresas%/%empresas%

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @dgirona,

    The function that saves/updates the permalink is only called within the admin dashboard by default.

    To make the plugin generate the post’s permalink after they are published with front-end form you will need to use additional code snippet:

    function pm_generate_uri_after_post_saved($post_id, $type, $args, $form, $action) {
        if(class_exists('Permalink_Manager_URI_Functions') && $type == 'insert_post') {
            $custom_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id, false, true);
            Permalink_Manager_URI_Functions::save_single_uri($post_id, $custom_uri, false, true);
        }
    }
    add_action('acfe/form/submit/post', 'pm_generate_uri_after_post_saved', 9, 5);

    Could you paste it to functions.php file in your child theme directory?

    Thread Starter dgirona

    (@dgirona)

    Hello Maciej,

    I have copied it to the bottom of the child theme’s functions file. After the function that creates the custom post type and the taxonomy. It does not work.

    The test:

    https://marketingonline.solucionesmallorca.com/empresas/test/

    But the correct url should be:

    https://marketingonline.solucionesmallorca.com/empresas/ocio-entretenimiento/test/

    ex.

    https://marketingonline.solucionesmallorca.com/empresas/ocio-entretenimiento/alquiler-barcos-y-lanchas/oasis-catamaran-descuentos-especiales-para-grupos-y-eventos/

    Any ideas?
    Thanks for the help Maciej,

    Plugin Author Maciej Bis

    (@mbis)

    Hi @dgirona,

    I managed to trigger this hook using a sample ACF front-end form after I linked the category dropdown to ‘Save Post’ action like this:

    View post on imgur.com

    There is one alternative possibility here. You can automatically update the post’s permalink whenever the ‘categorias_empresas’ term selection is saved to the database:

    function pm_generate_post_permalink($post_id, $terms, $tt_ids) {
    	
    	if(class_exists('Permalink_Manager_URI_Functions') && $taxonomy == 'categorias_empresas') {
    		$custom_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id, false, true);
    		Permalink_Manager_URI_Functions::save_single_uri($post_id, $custom_uri, false, true);
    	}
    	
    }
    add_action('set_object_terms', 'pm_generate_post_permalink', 9, 3);
    Thread Starter dgirona

    (@dgirona)

    Hello again, I have tried the new script and it doesn’t work : (

    The form is assembled with the plugin ACF Frontend Pro by Shabti Kaplan.

    Will that be the problem?

    I can give you access to wordpress by mail.

    Plugin Author Maciej Bis

    (@mbis)

    Hi @dgirona,

    Ok, ACF Frontend Pro uses a slightly different hook after the submitted post is published:
    https://www.frontendform.com/acf_frontend-save_post/

    function pm_generate_uri_after_post_saved($form, $post_id) {
        if(class_exists('Permalink_Manager_URI_Functions')) {
            $custom_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id, false, true);
            Permalink_Manager_URI_Functions::save_single_uri($post_id, $custom_uri, false, true);
        }
    }
    add_action('acf_frontend/save_post', 'pm_generate_uri_after_post_saved', 9, 2);

    Because I adhere to the www.ads-software.com forum’s security requirements, I am not permitted to have back-end access to any user’s website (even the staging/development one).

    Best regards,
    Maciej

    Thread Starter dgirona

    (@dgirona)

    It has worked perfectly, thank you very much again Maciej : )

    Plugin Author Maciej Bis

    (@mbis)

    No problem at all. If you have the chance, I would really appreciate it if you could submit your review on this page:
    https://www.ads-software.com/support/plugin/permalink-manager/reviews/

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Links are not automatically updated’ is closed to new replies.