How to filter out post type meta?

I have used this code to filter out the post type and it works fine when showing filtered results:

add_filter('wpseo_title', 'vehicle_listing_title');

function vehicle_listing_title( $title )
{
      if ( 'vehicles' != $post->post_type )

    {

    $location = get_the_terms($post->ID, 'vehicle_location');

    $model = get_the_terms($post->ID, 'vehicle_model');

    $title="";

    if($model && $model[0]) $title .= $model[0]->name . ' used';
    else $title .= 'Used';

    $title .= ' cars for sale';

    if($location && $location[0]) $title .= ' in ' . $location[0]->name;

    $title .= ' on ' . get_bloginfo('name');

    return $title;
  }

  return $title;
}

What I’m trying to achieve is…

  1. I want the code to return the post type meta when the url is on www.example.com/postype

  2. I want the code to return the $title even when there isn’t any content on the post type. I’m thinking something that would function like hide_empty=>false. right now it returns like this used cars for sale on sitename when there isn’t any content.

0

Leave a Comment