简体   繁体   English

如何从一页到另一页获取POST ID

[英]How to Get POST ID from one page to another page

I have created a message system in wordpress. 我已经在wordpress中创建了一个消息系统。 There sa consultation page fr each user.also a sidebar with certain menus. 每个用户都有一个咨询页面,还有带有某些菜单的侧边栏。 when the submit button is clicked the admin reviews the question and answers it. 单击提交按钮后,管理员将查看问题并回答。 The message will be shown in the inbox sidebar menu on the same consultation page. 该消息将显示在同一咨询页面上的收件箱侧边栏菜单中。

but whtever i tried am not getting the reply message of the corresponding user. 但是,无论如何我都没有得到相应用户的回复消息。 my problem is that when i defined the link for inbox there is no id being passed.later in tht particular page whtever id s am calling its bring up the page id only and nothing else. 我的问题是,当我定义收件箱的链接时,没有传递任何id。稍后在特定页面中,只有id调用它时才显示页面ID,而没有其他内容。

This is the sidebar code: 这是侧边栏代码:

<li>
    <a href="<?php echo site_url();?>/inbox/?id=<?php echo get_current_user_id();?>"><i class="fa fa-sort-alpha-asc " aria-hidden="true"> </i> <span style="margin-left:10px;">Inbox</span>  </a>
</li>

now its bringing the id = 1. no matter which user it is. 现在,它带来的ID =1。无论是哪个用户。

this is the inbox code: 这是收件箱代码:

<?php
global $post;
$idd= $post->ID;

$title= $post->post_title;
var_dump($title);

echo "<div class= 'col-lg-4'><table style='width:500px;'><tr><td><b>Reply:</b>&nbsp;".get_post_meta( $idd, 'docreply', true)."</td></tr></div>";

echo "<div class= 'col-lg-4'><table style='width:500px;'><tr><td><b>Amount:</b>&nbsp;".get_post_meta( $idd, 'amount', true)."</td></tr></div>";

[1]:https://i.stack.imgur.com/9b2pL.p

you can get the post id by using get_the_ID() function. 您可以使用get_the_ID()函数获取帖子ID。

<?php
echo get_the_ID();
?>

Where is the message data saved? 消息数据保存在哪里?

I see you calling the page URL with the ID of the currently logged user. 我看到您用当前登录用户的ID调用页面URL。

Later, you're using the ID of the page then fetching two meta values and displaying them. 稍后,您将使用页面的ID,然后获取两个元值并显示它们。

If you're using post meta, use the ID of the user that is logged in and get the meta value by using get_user_meta - https://codex.wordpress.org/Function_Reference/get_user_meta 如果使用的是发布元,请使用登录用户的ID并通过使用get_user_meta- https: //codex.wordpress.org/Function_Reference/get_user_meta获取元值

More code would help solve this easier :) 更多代码将有助于更轻松地解决此问题:)

Finally i have found a solution to my problem. 终于我找到了解决我问题的方法。 I updated the post_meta values in to my user_meta and in the page where i need to display the data, i called the current user id and called the user_meta 我将post_meta值更新为我的user_meta,并在需要显示数据的页面中将其更新,我将其称为当前用户ID,并将其称为user_meta

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM