ajax写删除程序,ajax处理程序删除标记

我得到它的工作。 $ post_ids和$ post_id有问题。它被分配了两倍。

这是我对任何人谁喜欢有它最终代码:

它能做什么。它在点击链接时指定一个标签并取消指定旧链接。我用它来让用户将附件的状态更改为已存档或未更改。

的HTML:

beard.png

制作taguntagfunc.php在您的主题,文件夹

include("../../../wp-load.php");

$selection = $_REQUEST['selection'];

$post_id = $_REQUEST['pid'];

$tag= $_REQUEST['tag'];

if($tag==ap_aktuell){

$untag= 'ap_aktuell';

$inserttag= 'ap_archiv';

untag_post($post_id,$untag);

wp_set_post_tags($post_id, $inserttag, false);

}

elseif($tag==ap_archiv){

$untag= 'ap_archiv';

$inserttag= 'ap_aktuell';

untag_post($post_id,$untag);

wp_set_post_tags($post_id, $inserttag, false);

}

使用这个js脚本来听的链接,已经.json_click_handler2分配。它会在rel和ALT-属性传递给函数:

jQuery(document).ready(function(){

jQuery('.json_click_handler2').click(function(){

var c = jQuery(this).attr('rel');

var d = jQuery(this).attr('alt');

jQuery.ajax({

url: 'wp-content/themes/kleinraumv4_ap/taguntagfunc.php',

data:{

'pid' : d,

'tag' : c

},

dataType: 'html',

success:function(){

window.location.reload(true);

},

error: function(errorThrown){

alert('error');

console.log(errorThrown);

}

});

});

}); 到functions.php使用

最后下面的函数之一,实际上你想要做什么。过渡时期援助团。

function untag_post($post_ids,$tags)

{

global $wpdb;

if(! is_array($post_ids))

{

$post_ids = array($post_ids);

}

if(! is_array($tags))

{

$tags = array($tags);

}

foreach($post_ids as $post_id)

{

$terms = wp_get_object_terms($post_id, 'post_tag');

$newterms = array();

foreach($terms as $term)

{

if (!in_array($term->name,$tags))

{ //$term will be a wordpress Term object.

$newterms[] = $term;

}

}

wp_set_object_terms($post_id, $newterms, 'post_tag', FALSE);

}

}

function get_tag_ID($tag_name) {

$tag = get_term_by('name', $tag_name, 'post_tag');

if ($tag) {

return $tag->term_id;

} else {

return 0;

}

}

我用get_tag_ID获取当前分配的标记的ID来区分归档和不归档。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值