1

私はcustomize_registerの作用の下で、現在のqueried_objectのIDを取得しようとadd_action下のポスト、ページまたは分類IDを取得する方法( 'customize_register'、...) - WP ...

// call action customize register 
add_action('customize_register','register_customize_options'); 


//customize register callback function 
function register_customize_options($wp_customize){ 

//if is page customize preview 
if(is_page()): //not work 

    $ObjID = get_the_ID(); //not work 

//if is any taxonomy customize preview 
elseif (is_tax()) : //not work 

    $ObjID = get_queried_object()->term_id; //not work 

endif; 

// obj $wp_customize; 
// var_dump($wp_customize); //not found any ID 

//rest of code... 

} 

をカスタマイズまた、私は取得してみてくださいページIDはurl_to_postid($_GET['url'])で、これはユーザーがページ上でカスタマイズを開いた場合にのみ機能します。

どのように動的にオブジェクトIDを取得するには、customize_registerアクションの下で?

答えて

0

投稿、ページまたは分類IDを取得する方法は? function.phpの下の関数を追加することができます

//customize register callback function 
function register_customize_options($wp_customize){ 

    if(is_page() || is_single()) 
    { 
     $ObjID = get_the_ID(); 

    } 

    $term = get_queried_object(); 
    if ($term) 
    { 
     if (is_category() || is_tag() || is_tax()) { 
      $ObjID = $term->term_id; 
     } 
    } 

    return $ObjID; 

    // obj $wp_customize; 
    // var_dump($wp_customize); //not found any ID 

    //rest of code... 

} 
add_action('customize_register','register_customize_options'); 
+0

ありがとうございましたが、それは私にとってはうまくいきません。 あなたはWPのインストールでそれを試していますか? –

関連する問題