【发布时间】:2014-04-08 15:30:08
【问题描述】:
如何获取在永久链接中传递的帖子 ID。在wordpress中,我看到了这个:
href="<?php echo get_permalink($post->ID); ?>"
使用JQuery get 方法我可以将href 属性传递给php 中的进程。代码是:
<script type="text/javascript">
$(document).ready(function(e) {
$('Selector').on('click', function(){
var href = $(this).attr('href');
$.get('url',
{
'post_id' : href
},
function(data){
alert(data);
});
return false;
});
});
</script>
它会根据需要给我发布永久链接,但我如何获得$post->ID。我在获得永久链接后使用了url_to_postid 方法,但这不起作用,所以如果可能的话,我想获得$post->ID。谢谢你的帮助
【问题讨论】:
-
我在获得永久链接后使用了
url_to_postid方法,但它不起作用:您收到错误消息了吗? -
我得到 0,
WordPresscodex 也提到过,失败时你会得到 0 -
get_permalink在循环内? -
我看不到任何
id属性(当您在 jquery 中使用时)请发布您的完整代码。 -
对不起,我现在已经编辑了我的问题,我还是得到了答案,谢谢你的帮助