generate custom permalink based on a custom field

Try this plugin Custom Post Type Permalinks, it allows you to set permalinks for custom post types. If your client does not want additional plugin then this plugin is also available on GitHub you can fork it or include this functionality in your own plugin or your functions.php. In order to use anything dynamic in … Read more

Remove “-2” from a Toolset Types URL with the same post name

It can be done by using the request filter. Something like this function alter_the_query($request) { return array(‘page’ => 1, ‘pagename’ => null); } add_filter(‘request’,’alter_the_query’); Here it forces display of post 1, though of course you will want to do a query to determine the ID. For that, it might prove easiest to first parse the … Read more

Link for the page archive for posts, like using custom post types with get_post_type_archive_link

I use a shortcode: function shortcode_article_list() { $posts_array = get_posts( array(‘posts_per_page’ => -1, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’) ); $output=”<ul>”; foreach ($posts_array as $post) { $a = explode(‘ ‘, $post->post_date); $output .= ‘<li><a href=”‘ . home_url(“https://wordpress.stackexchange.com/”) . $post->post_name . ‘.html”>’ . $post->post_title . ‘</a> (‘ . $a[0] . … Read more

Gutenberg Editor: dynamicaly change slug field with an ACF field

I’ve found a way to dynamicaly change the slug field with the short title custom field. jQuery(document).ready(() => { const acfField = ‘field_61f8bacf53dc5’; const inputShortTitle = document.getElementById(‘acf-‘ + acfField); const slugify = (str) => { return str.toLowerCase().replace(/ /g, ‘-‘) .replace(/-+/g, ‘-‘).replace(/[^\w-]+/g, ”); } const updateSlug = () => { wp.data.dispatch(‘core/editor’).editPost({slug: slugify(inputShortTitle.value)}); } if (inputShortTitle !== … Read more

How to get blog id from permalink?

the plugin “WDS Multisite Aggregate” store the blog identifier in a meta of the cloned post. then in the template file wich display the cloned posts, you can retrieve the home url of the original website with that : $blogid = $GLOBALS[“post”]->blogid; $blog_details = get_blog_details($blogid); // the home URL is in $blog_details->home I hope this … Read more