[Resolved] post_id used by item menu Page

Home Forums Support post_id used by item menu Page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #907260
    Sebastien

    Hi,

    I use a shortcode into the title of menu item that display a Custom Field Value (this is the actual main menu into the top bar -> submenu “Services”)
    At the moment I have to set either the field + post_id [field "my_key" post_id=1] or only the field
    [field "my_key"] and it will display the field value of the current post.

    I would like to add a third possibility: In fact, The shortcode is used in a menu item type Page that contains Custom Field Value I want to display is stored in the same post_id.
    I would like use a shortcode like that [field "my_key" post_id=item_menu_pageid] or directly by hook for a specific item menu.

    this is the function:

    add_shortcode('field', 'shortcode_field');
     
    function shortcode_field($atts){
         extract(shortcode_atts(array(
                      'post_id' => NULL,
                   ), $atts));
      if(!isset($atts[0])) return;
           $field = esc_attr($atts[0]);
           global $post;
           $post_id = (NULL === $post_id) ? $post->ID : $post_id;
           return get_post_meta($post_id, $field, true);
       }

    from https://www.isitwp.com/get-custom-field-value-with-shortcode/

    could you help?

    #907294
    Leo
    Staff
    Customer Support

    Hi there,

    Have you tried commenting on that post and see if the author is able to help?

    Looks like he is quite active on there.

    If not then maybe try an open forum for general WordPress questions like this:
    https://stackoverflow.com/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.