Support » Plugins » rewriting & wp_redirect problem

  • Resolved grosbouff


    Hi, i’m currently developping a classified ads plugin.

    For this; i created a custom post type (ads) and 3 main taxonomies (ad_type,ad_category,ad_tag).

    Let’s say we are looking for a red(ad_tag) car(ad_category) in the offers(ad_type).

    When you are browsing the ads and viewing the results, you can save the “search filters” used.

    It will save a user meta with the subscription (search filters) parameters; eg.

    umeta_id	user_id		meta_key	meta_value
       147		   1	   'ad_subscription'	array('ad_type'=>'offer','ad_category'=>'cars','ad_tag'=>'red');

    On the main ads page; a link for the user will be available; eg. /wordpress/ads/my-subscriptions/147.
    If I click on that link; it will load the subscription #147; fill the wp_query arguments with it;and the page will load the matching ads and display them in a custom way (because it’s a subscription page).

    Here’s my problem.
    Let’s say we saved this subscription.

    But now, what if we are not on the subscription page but that we are searching for a red car in the ad offers
    It is exactly the same arguments than in the subscription we saved.

    So I wrote a function to compare the searched arguments with every subscription’s arguments; so I can now if the search made already have been saved in a subscription.
    That’s one step.

    If the searched arguments ARE already saved in a subscription; I would like to REDIRECT to that subscription.
    And here i’m stuck. It makes an infinite loop.

    Could you see something that’s wrong in this ? :

    function ads_redirect_to_subscription(&$query) {
    	if ($query->query_vars['post_type']!='ad') return $query; //we are not searching for ads
    	if ($query->query_vars['ads_subscription']) return $query; //we ARE loading a subscription
    	$search = yclads_filter_query_args($query); //get ad search arguments
    	if(!$search) return $query; //no ad search arguments found
    		$subscription_id=self::args_are_already_subscription_id($search); //compare search arguments with subscriptions
    		if ($subscription_id!=$query->query_vars['ads_subscription']){

    Thanks a lot !

Viewing 1 replies (of 1 total)
  • I finally found out.
    Don’t think anyone will need this, but it can help :

    function redirect_to_subscription(&$query) {
    		global $wp_query;
    		if ($wp_query->query_vars['post_type']!='yclad') return $query;
    		//if ($query->query_vars['yclads_subscription']) return $query;
    		$search = yclads_filter_query_args($wp_query);
    		if(!$search) return $query;
    		if($q_subscription_id==$u_subscription_id) return $query;
Viewing 1 replies (of 1 total)
  • The topic ‘rewriting & wp_redirect problem’ is closed to new replies.