0

I have spent a whole day trying to resolve in issue. I'm trying to retrieve a custom varaible which is added by my plugin. I have tried testing the regex using the rewrite analyzer, which recognizes the regex is correct but when I use it I do not get the expected result

http://mysite.com/properties/property/2/

should return a var of property_id = 2, but this is nowhere to be found in var_dump($wp_query->query_vars);

Any Ideas?

public function __construct()
        {
            // register actions
          add_action('admin_init', array(&$this, 'admin_init'));
        } // END public function __construct
public function admin_init()
        {
$pholderid = 4;
add_rewrite_tag('%property_id%', '([^&]+)');
          add_rewrite_tag('%psearchparam%', '([^&]+)');
          $pholderid = get_option( 'vvpp_post_id' );            
          if (isset($pholderid)){
          //use placeholder to identify property details as post
          add_rewrite_rule("properties/property/([0-9]{1,})/([^/]*)/?",'index.php?post_type=properties&p='.$pholderid.'&property_id=$matches[1]','top');
          add_rewrite_rule("properties/property/([0-9]{1,})/?",'index.php?post_type=properties&p='.$pholderid.'&property_id=$matches[1]','top');
          }
          add_rewrite_rule("properties/page/([0-9]{1,})/([^/]*)/?",'index.php?post_type=properties&paged=$matches[1]&psearchparam=$matches[2]','top');        
          //might be needed
          flush_rewrite_rules();

}
1

You're adding the rewrite tag on admin_init, so it doesn't exist on front end requests. Add your rewrite stuff on init instead.

| improve this answer | |
  • Perfect. Sorry for the noob question. couldn't see for looking, sometimes need fresh eyes. – Lloydie.t Aug 11 '14 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.