Working with wordpress routes

0

Is it possible to work with custom routes within wordpress?

I'm building a website that consumes an api where the user can search for products.

I would like to customize the url of the site to determine pages as follows miite.com/static/city/boyr/here_to_my_product this url would be directed to a wordpress page.

att,

    
asked by anonymous 04.12.2016 / 00:12

1 answer

1

You're looking for the Rewrite API . It is used to customize the URLs so that you can fetch the values within your query in whatever form you need.

Example of Codex :

<?php
  function custom_rewrite_rule() {
    /**
     * add_rewrite_tag() cria "tags" que podem ser acessadas pelo 
     * objeto de query padrão, usando get_query_var()
     */
    add_rewrite_tag('%food%', '([^&]+)');
    add_rewrite_tag('%variety%', '([^&]+)');

    /**
     * add_rewrite_rule() cria regras para traduzir as queries em URLs
     * no formato desejado.
     *
     * A regra aqui cria a URL: http://example.com/nutrition/milkshakes/strawberry/
     * transformada em food=milkshakes e variety=strawberry
     */      
    add_rewrite_rule('^nutrition/([^/]*)/([^/]*)/?','index.php?page_id=12&food=$matches[1]&variety=$matches[2]','top');
  }
  add_action('init', 'custom_rewrite_rule', 10, 0);
?>

Links:

add_rewrite_rule ()

add_rewrite_tag ()

    
04.12.2016 / 02:10