Template and htacess Wordpress page

Asked

Viewed 32 times

-1

In Wordpress:

On a template page:

I have a link: <a href="http://localhost/wpcurso/exercicios-questoes/?id='.$row->id_exercicio.' " >' . $row->titulo . '</a>

That points to another template page: <?php /* Template Name: exercicios-questoes */ ?>

How to make this link friendly URL to the second template page?

My htacess is the Worpress standard:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpcurso/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpcurso/index.php [L]
</IfModule>

# END WordPress

1 answer

0

You need to request a GET in the functions of your theme and validate in the database if it matches this id, the title you pass is optional because you don’t need to pass, with PHP will get the id as follows $_GET('id'); if you assign this GET in a variable you will receive the id you passed in the URL, until then it is ok, then make an SQL query with WHERE id = '$id' As follows the example of Where I gave and see if it returns true or false, if return the exercise/question data just make the listing of it on this page. Follow a practical example of this:

if(isset($_GET['id']) && !empty($_['id'])){
         $id = $_GET['id'];

         global $wpdb; //Chamando função de banco do Wordpress para fazer uma consulta

      // Fazendo uma consulta e atribuindo a uma variável distinta
      $var = $wpdb->get_results('SELECT * FROM tabela WHERE id = '.$id);

      // Vendo o retorno da consulta  
      print_r($var);
      die;

}
  • I’m not using Function in this example. I already get the id from one page to another through a get on the template page, I receive and list the right one coming from the bank, I want to know what rule in htacess create to receive that link I put.

  • the question url works, but I wanted this http://localhost/wpcurso/exercicios-questoes/1 to work.

  • Test this: Rewriterule . /wpcurso/index.php/$1 [L]

  • with php and htacess could do normaemnte, but it seems to be a page inside the worpress and using Template Name: exercises-questoes maybe you have to do something different, I don’t know.

  • try to do what I sent you up on htaccess

  • I’m out of access now, tomorrow I’ll be, but it won’t interfere with wp? native pages categories, for example?

  • Go not, it looks like you’re using the Wordpress route if using /name think will, need to configure to receive id, if it is giving error.

  • for now just id to test, then I will insert the string id-xxxxxx but there is quiet.

  • if you put what I passed to Htaccess is already right..

  • was trying something like exercise-questoes/([0-9]) exercises-questoes/? id=1$

  • Thanks man, tomorrow I’ll test.

  • if you use it as I said it will be exercises-questoes? id=1

  • it works not, actually it gives error 500 if you insert this rule in htacess.

  • Then moio kkk, makes a plugin for this and passes a shortcode next to the page I create requesting the ID in the URL

Show 10 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.