1

I have url http://domain.com/real-estate-news/phuket-luxury-property-in-high-demand-ms Where "real-estate-news" is category and "phuket-luxury-property-in-high-demand-ms" is the post name . when I print $wp_query->query_vars['name']; it gives the post slug and $wp_query->query_vars['category_name'] gives the category slug.

I want to generate a new url like http://domain.com/real-estate-news/phuket-luxury-property-in-high-demand-ms/xyz

and want to get xyz in query var like

    echo $wp_query->query_vars['name']; // print "phuket-luxury-property-in-high-demand-ms"
    echo $wp_query->query_vars['category_name']; // print "real-estate-news"
    echo $wp_query->query_vars['section']; //print "xyz"

How to add section query var in wordpress please help me

2 Answers 2

0

Is this a Custom Post Type? If it is, you have more options than not. Within the register_post_type()'s array you can enter an argument for 'rewrite' to change the slug name and hack in specific rewrite rules for that particular CPT. I have put this project away because of its complexity and if you find an answer I'd love to hear it. Here is my notes on the matter.

register_post_type(array(
//options
'rewrite'    => array( 
'slug'       => 'beach', //a slug used to identify the post type in URLs.
'with_front' => false,
'feed'       => true,  
'pages'      => true 
), 

dreamdare.org

shibashake.com1

shibashake.com2

Beware of wp.tutsplus very often misinformation is offered there by authors themselves.

wp.tutsplus.com

Sign up to request clarification or add additional context in comments.

1 Comment

No, this is not custom post type. this is simple post
0

The way I managed to do this is adding a rewrite rule.

This will look very similar to the one that custom post type creates but also receives a third parameter. so in your case the rewrite rule would look like this

add_rewrite_rule( 
  // post-type      | post-slug          | section           
  '^real-state-news/([^/]+)(?:/([0-9]+))?/([^/]+)/?$',
  //                                                    | Here the section is added
  'index.php?post_type=real-state-news&name=$matches[1]&section=$matches[3]',
  'top'
);

//You then need to add a tag to it
add_rewrite_tag('%section%','([^&]+)');

// At this point, you should be able to grab that param
get_query_var('section')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.