Support

Account

Home Forums General Issues Shortcode post_id function for custom post type name?

Solving

Shortcode post_id function for custom post type name?

  • Hi I am having to use multiple shortcodes on several pages as Divi theme isn’t playing nicely.
    So when using about 100 on a page like this: [acf field="about_page_title" post_id="277888"]
    When I am moving hosts and exporting the pages and importing back in on the new clients website I am worried about this post_id number changing.

    So I am trying to get a function that will enable a custom post type name e.g. aboutcontacts to use instead of id number.

    I have seen a plugin using this:

    
    global $post;
    $fieldValue =  get_field($attrs['field'], $post->ID);
    // var_dump($fieldValue);
    echo $this->container['acf_shortcode']->formatField($fieldValue, $attrs);
    

    Is there a way that I can create a shortcode that

    
    if( 'your_post_type' == $post->post_type ) {
            return $post->ID;
        }
    

    Then to create a new shortcode function based on this so that it won’t break when exporting importing pages.

    Sorry newbie with this, any help would be appreciated.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.