我没有使用ajax调用页面,而是调用了php文件。我只需要确保它在wordpress循环内,就可以使用短代码。它奏效了,完成了工作,我可以继续我的生活!
<script>
jQuery(document).ready( function() {
jQuery.ajax({
type: "GET",url: '/wp-content/themes/carshowcalendar-child/carslist.php',cache: false,dataType: 'html',success: function(data){
jQuery("select.ticket-meta").append(data);
},error: function(){ },complete: function(){ }
});
});
</script>
以及该carslist.php文件中的
<?php
define( 'WP_USE_THEMES',false ); // Don't load theme support functionality
require( '../../../wp-load.php' );
echo do_shortcode("[thecars]");
?>
我这样写的简码
/****the cars shortcode*****/
function addcars() {
$current_user = wp_get_current_user();
$userID = $current_user->ID;
$currentuser_ID = 'user_'.$userID; ?>
<?php if( have_rows('my_cars',$currentuser_ID) ): ?>
<?php while( have_rows('my_cars',$currentuser_ID) ): the_row(); ?>
<option value="<?php echo the_sub_field('year'); ?> <?php echo the_sub_field('make'); ?> <?php echo the_sub_field('model'); ?> <?php echo the_sub_field('color'); ?>"><?php echo the_sub_field('year'); ?> <?php echo the_sub_field('make'); ?> <?php echo the_sub_field('model'); ?> <?php echo the_sub_field('year'); ?> <?php echo the_sub_field('color'); ?></option>
<?php endwhile; ?>
<?php endif; ?>
<?php
}
add_shortcode( 'thecars','addcars' );
本文链接:https://www.f2er.com/3149278.html