Skip Navigation

[Resolved] get_permalink() does not work with Ajax now

This support ticket is created 3 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 7 replies, has 2 voices.

Last updated by jeffC-3 3 years, 2 months ago.

Assisted by: Jamal.

Author
Posts
#2172455
map_popup.jpg

I have been using Toolset and the Mappress plugin (hidden link) for years to create my winery map page hidden link.

Lately, I noticed the title in an icon's popup is not using the correct link to the custom post type that was created by Toolset. Here's how to reproduce.
1. Go to the winery map.
2. Click on an icon on the map.
3. Detail will pop up including Title, Address, website, and Winery Page which is a page with a Toolset View.

The Title should have the same URL as the Winery Page URL. However, where it should be "winery/tx", it shows up as "0000/00".
I contacted the Mappress plugin owner thinking it was a problem with his plugin.

He said all he is doing is a get_permalink(). I tried various things and it does work correctly for other items and when I include a $postID. He then said:
My guess is the Types plugin isn’t providing the correct permalink when get_permalink() is used in an AJAX call.

It used to always work correctly and since I have a staging with old data from June, I noticed it also failed with that code from Mappress and Toolset.

Did something change with Toolset recently so get_permalink() does not work in an AJAX call now? Any other suggestions?

#2172837

Hello and thank you for contacting Toolset support.

I am keen to think that the issue is caused by another component(plugin, custom code). Because the default permalinks for custom post types should be hidden link whereas you currently have an additional fragment. I would expect for a post to have hidden link instead of hidden link

Please try to check without Toolset. You will need to register the same custom post type using custom code. It has to have the same slug. https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/

If you are unsure how to do it, allow me temporary access and I'll try it. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#2172943

Hi Jamal,
Thank you for the reply. My Toolset custom post type for winery actually has the custom URL set to "winery/tx". I thought at one time I would use the different states instead of just TX, so that's why I did it that way. It worked fine back at that time and unfortunately I cannot identify when it broke. Any other suggestions?

#2173121

Can I get access to your website and check how the permalinks will get generated if we exclude Toolset from the equation?
I'll need FTP access too. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#2173809

Thank you for the credentials. I don't want to seem running from my responsibility, but I still think that this issue is not from Toolset. In fact, I am very sure that it has nothing to do with Toolset. If you can convince me of the opposite, we'll, all(Toolset team), do our best to help.

In fact, I have registered the same custom post type, using custom code, and I deactivated Toolset Types and Toolset Views, and I still see the issue. Please check the theme's functions.php file. I have added custom code to register the custom post type, and then I have deactivated the Toolset plugins, and the issue is still reproducible. You can check it from your side, by uncommenting the last line(540) of the file and deactivating Toolset plugins.

This is the code that I have used to register the post type:

// Register Custom Post Type
function winery_custom_post_type() {

	$labels = array(
		'name'                  => _x( 'Wineries', 'Post Type General Name', 'text_domain' ),
		'singular_name'         => _x( 'Winery', 'Post Type Singular Name', 'text_domain' ),
		'menu_name'             => __( 'Post Types', 'text_domain' ),
		'name_admin_bar'        => __( 'Post Type', 'text_domain' ),
		'archives'              => __( 'Item Archives', 'text_domain' ),
		'attributes'            => __( 'Item Attributes', 'text_domain' ),
		'parent_item_colon'     => __( 'Parent Item:', 'text_domain' ),
		'all_items'             => __( 'All Items', 'text_domain' ),
		'add_new_item'          => __( 'Add New Item', 'text_domain' ),
		'add_new'               => __( 'Add New', 'text_domain' ),
		'new_item'              => __( 'New Item', 'text_domain' ),
		'edit_item'             => __( 'Edit Item', 'text_domain' ),
		'update_item'           => __( 'Update Item', 'text_domain' ),
		'view_item'             => __( 'View Item', 'text_domain' ),
		'view_items'            => __( 'View Items', 'text_domain' ),
		'search_items'          => __( 'Search Item', 'text_domain' ),
		'not_found'             => __( 'Not found', 'text_domain' ),
		'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
		'featured_image'        => __( 'Featured Image', 'text_domain' ),
		'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
		'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
		'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
		'insert_into_item'      => __( 'Insert into item', 'text_domain' ),
		'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
		'items_list'            => __( 'Items list', 'text_domain' ),
		'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
		'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
	);
	$rewrite = array(
		'slug'                  => 'winery/tx',
		'with_front'            => true,
		'pages'                 => true,
		'feeds'                 => true,
	);
	$args = array(
		'label'                 => __( 'Winery', 'text_domain' ),
		'description'           => __( 'This is a list of wineries', 'text_domain' ),
		'labels'                => $labels,
		'supports'              => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
		'taxonomies'            => array( 'post_tag' ),
		'hierarchical'          => false,
		'public'                => true,
		'show_ui'               => true,
		'show_in_menu'          => true,
		'menu_position'         => 5,
		'show_in_admin_bar'     => true,
		'show_in_nav_menus'     => true,
		'can_export'            => true,
		'has_archive'           => true,
		'exclude_from_search'   => false,
		'publicly_queryable'    => true,
		'rewrite'               => $rewrite,
		'capability_type'       => 'page',
	);
	register_post_type( 'winery', $args );

}
add_action( 'init', 'winery_custom_post_type', 0 );

Please reach out, again, to the Mappress plugin team, and share this thread with them, maybe they can suggest something else.

And we'll remain at your disposal, if anything suggests that Toolset is causing this issue, we'll do our best to help.

#2173989

Hi Jamal. Thank you for checking. I will pass along the information to the Mappress plugin team and update this after they take a look.

#2174177

Thank you! I'll set this ticket as waiting for your feedback. It should be kept open for 2 weeks. And you will receive reminders' notifications before it gets closed.

#2175563

The Mappress plugin developer found a bug in the code. He did not realize there was a custom rewrite rule. I verified the fix with a prerelease version and he will be releasing a new version of the plugin. Thank you for the help!