WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] An Alternative To do_shortcode (2 posts)

  1. Ryan Ball
    Member
    Posted 3 years ago #

    Hi Everyone. Please bear with me, as I'm not 100% sure what I need...

    I am using a class within a custom plugin to provide a custom post type. As part of the post type there are five meta keys for storing an address (e.g. building, street, city, state, zip).

    To keep the loop as simple as possible, I want to offer an easy way to return the whole address as a single string.

    At the moment I have achieved this by adding a shortcode to the custom post type and calling it from wihtin the loop via do_shortcode.

    Can anyone suggest a better/simplier way to achieve the same result?

  2. Ryan Ball
    Member
    Posted 3 years ago #

    Well, I found one alternative - but not sure if its reccommend...

    I added a hook to the the_post action which appended an extra value to the $post object.

    add_action('the_post', array(&$this, 'the_post'));

    function the_post($post)
    	{
    		global $post;
    
    		$custom = get_post_custom($post->ID);
    		$building = $custom['building'][0];
    		$street = $custom['street'][0];
    		$city = $custom['city'][0];
    		$county = $custom['county'][0];
    		$postcode = $custom['postcode'][0];
    
    		$address = new AircooledBugsAddress($building, $street, $city, $county, $postcode);
    
    		$post->post_event_address = $address->get_formatted_address();
    
    		return $post;
    	}

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.