I am using Custom Post Type Permalinks plugin to set a custom structure for my permalinks using only settings/general in the admin area of WordPress.
The custom permalink structure I am using is :
/%postname%/%product_category%/
In addition, I have under my single-CPT.php
page a select tag that triggers some jquery/ajax actions. When I remove the custom permalink structure, which automatically activates the default permalink strucure, everything works like a charm. But after activating the above structure, the DIV that should display results resturned by jquery/ajax,embeds the whole page in a weird manner.
My jquery code is:
$('select.select').change(function(e) {
e.preventDefault();
var value = $('select.select option:selected').val();
create_ayat_selectCPT(value); // AJAX function
})
Thank you very much for your help, I am 2 days digging to find the solution.
Note that I am using cutom post types in my website.
Edit:
Taking into consideration Damon answer, the permalink structure affects the behaviour of the jquery/ajax function. In fact, if I change to /%product_category%/%postname%/
, the Ajax call is executed but with no success.
Result: I have actually the alert displaying the error message.
The function jquery/ajax function is :
function create_ayat_selectCPT(str)
{
$.ajax({
type: "GET",
url: "wp-admin/admin-ajax.php",
dataType: 'html',
data: ({ action: 'createAyatSelectCPT', id: str}),
success: function(data){
$('#second-select').html(data);
},
error: function(data)
{
alert("Your browser broke create ayat cpt select!");
return false;
}
}); //ajax
return false;
}
Under functions.php:
function createAyatSelectCPT() {
$ca=$_GET['id'];
?>
<form method="post" action="">
<select class="select2" id="selectid">
<?php
$my_query = new WP_Query();
$args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_category',
'terms' => array($ca)
)
)
);
$my_query->query($args);
if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
?>
<option value="<?php the_ID();?>"><?php the_title(); ?></option>
<?php
endwhile;
endif;
wp_reset_query();
die();
?>
</select>
</form>
<?php
}
add_action('wp_ajax_createAyatSelectCPT', 'createAyatSelectCPT');
add_action('wp_ajax_nopriv_createAyatSelectCPT', 'createAyatSelectCPT');
The concerned HTML tag to modify is:
<div id="second-select">...</div>
Edit 2 After installing Firebug :
404 Not Found File: http://localehost.com/enc/products/stuff/stuff/wp-admin/admin-ajax.php?action=createAyatSelectCPT&id=132
Then, the problem comes from the location admin-ajax.php
. this file doesn’t exist in this location. So the new permalink structure requires that I modify the path to admin-ajax.php in my jquery script file.
How do you know what function is messing up the divs?
Is your jquery/ajax code changing the divs etc? If so, can you provide us with the corresponding code snippet?
Also, does it happens when you use “/%postname%/%product_category%/” custom permalinks or any other custom ones as well.
Try using the Firebug plugin, and provide us with little more info so we can help you with this issue quickly and effectively. Screenshots will also help.
Download Firebug: http://getfirebug.com/