WordCent
WordCent

Reputation: 727

either syntax issue or wordpress Post ID Issue

<?php $imvi = get_post_meta('312', 'bmeta_o', true); ?>

The above works fine when hardcoded Wordpress post ID is used = '312'

But the theme demands that this should come through some selection of post done in the theme customizer.

I tried various versions → $selected_post_id = echo get_theme_mod('my_setting');

 1. <?php $imvi = get_post_meta(echo $selected_post_id;, 'bmeta_o',
    true); ?>
 2. <?php $imvi = get_post_meta(echo '', 'bmeta_o', true); ?>
 3. <?php $imvi = get_post_meta($selected_post_id;, 'bmeta_o', true); ?>

But none of them worked.

  1. either I am not using correct PHP syntax or
  2. $selected_post_id = echo get_theme_mod('my_setting'); → This has some flaw and it is not pulling the WordPress post ID correctly

Please let me Know if you need any other information.

Upvotes: 0

Views: 31

Answers (1)

Igor Yavych
Igor Yavych

Reputation: 4228

  1. You have echo inside the call function and ;, both of which will cause syntax error.
  2. You also have echo and just empty string. Will not work.
  3. Closest one, but that ; will still cause an error.
    Correct one (assuming that $selected_post_id actually contains post ID)
    $imvi = get_post_meta($selected_post_id, 'bmeta_o', true);

Upvotes: 1

Related Questions