parsing - WordPress custom post type permalink structure with custom field value -


i trying modify url structure of custom post type 'project'.

i url structure follows:

http://localhost/project/%location%/project-name

%location% custom field value associated post.

so if had post called 'test' custom field value of 'seattle', url this:

http://localhost/project/seattle/test

i have semi completed following:

function test_query_vars( $query_vars ) {     $query_vars[] = 'location';     return $query_vars; } add_filter( 'query_vars', 'test_query_vars' );  function test_init() {     $wp_rewrite->add_rewrite_tag( '%project%', '([^/]+)', 'project=' );     $wp_rewrite->add_rewrite_tag( '%location%', '([^/]+)', 'location=' );      $wp_rewrite->add_permastruct( 'project', 'project/%location%/%project%', false );      // register post type     register_post_type( 'project',          array(             'labels' => $labels,             'public' => true,             'rewrite' => false,             'has_archive' => true,             'menu_position' => null,             'supports' => array ( 'title', 'editor', 'thumbnail', 'page-attributes', 'excerpt', 'comments', 'author' ),             'yarpp_support' => true,         )     ); } add_action( 'init', 'test_init' ); 

there few problems this:

  1. the location custom field in url can anything. if go http://localhost/project/atlanta/test , location custom field 'seattle', still bring desired post. should 404 not found since 'test' post has custom field 'location' value set 'seattle'.
  2. if go http://localhost/project/seattle, bring blog, should bring projects have custom field value set 'seattle'.
  3. the archive post type having 404, e.g. http://localhost/project/ should displaying projects.

i have tried modifying query using following still not working:

function test_parse_query( $query ) {     if ( 'project' == $query->query_vars['post_type'] ) {          $query->set('meta_query', array(             array(                 'key' => 'project_location',                 'value' => $query->query_vars['location']             )         ));     }      return $query; } add_filter( 'parse_query', 'test_parse_query' ); 

any appreciated :)


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -