Shortcodes in Custom Fields

This topic contains 7 replies, has 3 voices, and was last updated by  Paolo 9 years, 4 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #25365

    Jerry Medina
    Free User
    Post count: 9

    Is there a way to add Shortcode support into custom fields?
    Am using Custom Post plugin for WPGeodirectory.
    Just that I don’t have access to the account who bought the plugin, but this was asked before. hehe

    #25366

    Jeff
    Buyer
    Post count: 188

    It is possible, but would require a bit of work in the core plugin and may cause issues.

    Can you explain what you’re looking to do (beyond the obvious)? What shortcodes, why etc?

    #25510

    Jerry Medina
    Free User
    Post count: 9

    I want to add a shortcode that lets me link other posts from a certain Post Type.

    http://mallsmexico.com/wp-admin/admin.php?page=geodirectory&tab=gd_plazas_fields_settings&subtab=custom_fields&listing_type=gd_plazas here exactly.

    #25511

    Jeff
    Buyer
    Post count: 188

    If you use a custom field of type URL, you can put a link in there.

    Perhaps I’m still missing something. For example, what shortcode do you want to put in there? Which plugin or theme is giving you that shortcode?

    #25512

    Jerry Medina
    Free User
    Post count: 9

    [display-posts post_type=”gd_eventos” include_excerpt=”false” posts_per_page=”3″]
    Plugin is https://wordpress.org/plugins/display-posts-shortcode/

    (:

    #25514

    Jeff
    Buyer
    Post count: 188

    I see – it’s a list of related posts basically.

    I assume you don’t want to put that in the body of the listing because users can change/remove it?

    I’m trying to think of another way to accomplish this. Running every custom field through the shortcode process would add a lot of load to a site.

    #25520

    Jerry Medina
    Free User
    Post count: 9

    no, what I want to do is add a new custom field such as a textarea or HTML where I can add in a shortcode so the list of posts shows in that particular tab

    That’s basically it.
    Ps: thanks for the swift replying 😀

    #25589

    Paolo
    Site Admin
    Post count: 31206

    You should add a custom tab (via php) and use the default wp shortcode API call

    <?php echo do_shortcode( $content ) ?>

    inside the function that will add content in the new tab.

    To add a tab with label ‘New Tab’ do the following in ur theme functions.php file:

    
    
    
    add_filter('geodir_detail_page_tab_list_extend', 'geodir_detail_page_tab_list_extend') ;
    
    function geodir_detail_page_tab_list_extend($tab_array)
    {
     	$tab_array['my_new_tab'] = array( 
    										'heading_text' =>  __('New Tab',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'my_new_tab'),
    										'tab_content' => ''
    									);
    	return $tab_array ;
    }
    

    Now for the second part, to show Content when user click on that tab, do this:

    
    
    
    add_action('geodir_after_tab_content' ,'geodir_my_new_tab_content');
    function geodir_my_new_tab_content($tab_index)
    {
    	if($tab_index =='my_new_tab')
    	{
                   echo do_shortcode( $content );
    	}
    }
    

    Please make sure that ‘my_new_tab'(tab index) is same as array index created in first step.

    Obviously change $content inside the do_shortcode call to whatever shortcode name you need to use.

    Let us know how you went.

    Thx

Viewing 8 posts - 1 through 8 (of 8 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket