2016-05-07 8 views
1

このコードは、get_post_meta機能を使用して特定の投稿にボタンを追加するように設計されています。このボタンを特定の投稿に表示するには、get_post_meta関数をどのように変更しますか?私は既に$post->IDパラメータを '1464'に変更しようとしました。これは使用するポストIDです。get_post_meta - WordPress

function custom_listify_single_job_listing_actions_after() { 
    global $post; 

    $url = get_post_meta($post->ID, 'your_custom_meta_key', true); 

    echo '<a href="' . esc_url($url) . '" class="button">My Button</a>'; 
} 
add_filter('listify_single_job_listing_actions_after', 'custom_listify_single_job_listing_actions_after'); 
+1

ここにお問い合わせくださいhttps://wordpress.stackexchange.com –

+0

クロス投稿:http://wordpress.stackexchange.com/q/225967/46066 –

答えて

1

あなただけの特定のポストにこのコードを実行したい場合は、そのポストのIDをチェックするifステートメントを追加する必要があります。

あなたのコードは次のようになりする必要があります:あなたは彼らがしたい記事にこれらのみ実行のよう両方

if($post->ID == 1464){ 
    $url = get_post_meta($post->ID, 'your_custom_meta_key', true); 

    echo '<a href="' . esc_url($url) . '" class="button">My Button</a>'; 
} 

この単純get_post_meta()機能とecho文をラップします。他の投稿はコードを無視します。

関連する問題