• Hello folks,

    I’m new to WordPress and tried to start writing my first own plugin the last days. Currentley I try to set up an specific url structure. I’ve written a plugin with a hook:

    function pgnet_test_createRewriteRules($rewrite) {
    	global $wp_rewrite;
    
    	// relevant tokens
    	$token_tour = '%tour%';
    	$token_leg  = '%leg%';
    
    	// register url tags
    	$wp_rewrite->add_rewrite_tag($token_tour, '(.+?)', 'tour=');
    	$wp_rewrite->add_rewrite_tag($token_leg,  '(.+?)', 'leg=');
    
    	// url structure & add rewrite rule
    	$url_structure = $wp_rewrite->root . 'live-database/' . $token_tour . '/' . $token_leg;
    	$url_rewrite   = $wp_rewrite->generate_rewrite_rules($url_structure);
    
    	return ($url_rewrite + $rewrite);
    }
    
    add_filter('rewrite_rules_array', 'pgnet_test_createRewriteRules');

    So when I try to access a url of that kind, like mydomain.tld/live-database/tourname/legname I expected to get the defined tags as a parameter in the query vars but it doesn’t work. What should I have to do?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter 723007

    Here is an

    printr ($wp_query);

    for /livedatabase/tour2008/leg21/:

    WP_Query Object
    (
        [query_vars] => Array
            (
                [name] => leg21
                [category_name] => livedatabase/tour2008
                [error] =>
                [m] => 0
                [p] => 0
                [subpost] =>
                [subpost_id] =>
                [attachment] =>
                [attachment_id] => 0
                [hour] =>
                [static] =>
                [pagename] =>
                [page_id] => 0
                [second] =>
                [minute] =>
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [tag] =>
                [tag_id] =>
                [author_name] =>
                [feed] =>
                [tb] =>
                [paged] =>
                [comments_popup] =>
                [preview] =>
                [category__in] => Array
                    (
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
                [cat] =>
                [post_type] => post
                [posts_per_page] => 10
                [nopaging] =>
                [order] => DESC
                [orderby] => wp_posts.post_date DESC
            )
    
        [request] =>  SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.post_name = 'leg21' AND wp_posts.post_type = 'post'  ORDER BY wp_posts.post_date DESC
        [post_count] => 0
        [current_post] => -1
        [in_the_loop] =>
        [post] =>
        [comments] =>
        [comment_count] => 0
        [current_comment] => -1
        [comment] =>
        [found_posts] => 0
        [max_num_pages] => 0
        [is_single] =>
        [is_preview] =>
        [is_page] =>
        [is_archive] =>
        [is_date] =>
        [is_year] =>
        [is_month] =>
        [is_day] =>
        [is_time] =>
        [is_author] =>
        [is_category] =>
        [is_tag] =>
        [is_tax] =>
        [is_search] =>
        [is_feed] =>
        [is_comment_feed] =>
        [is_trackback] =>
        [is_home] =>
        [is_404] => 1
        [is_comments_popup] =>
        [is_admin] =>
        [is_attachment] =>
        [is_singular] =>
        [is_robots] =>
        [is_posts_page] =>
        [is_paged] =>
        [query] => Array
            (
                [name] => leg21
                [category_name] => livedatabase/tour2008
            )
    
        [posts] => Array
            (
            )
    
    )
    Thread Starter 723007

    Nobody can help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problems with own rewrite rules and query vars’ is closed to new replies.