How to get current post_id in function.php file

前端 未结 3 2034
时光说笑
时光说笑 2021-01-06 19:28

This is my function in function.php file

  function getcity(){
    global $wpdb;

    if($_POST[\'state\'])
            {
                $id=$_POST[\'state\         


        
3条回答
  •  执笔经年
    2021-01-06 20:03

    You want the global variable $post as documented here:

    http://codex.wordpress.org/Global_Variables

    Declare the $post global like so:

    global $post;
    

    Then you should be able to access the id of the post using $post->ID.

    Here is a more complete doc of the attributes available through the $post global: http://codex.wordpress.org/Function_Reference/$post

提交回复
热议问题