Custom js loop in wordpress -


help wp custom loop, have js script variable

<script> var prueba='chihuahua'; </script> 

i need pass var custom loop:

<?php     $catname = "<script>document.write(prueba);</script>";     echo $catname; // show correct pass js variable php variable     $posts = get_posts('category_name='.$catname);     foreach ($posts $post) {         echo "hola";     } ?> 

but not display posts, 4 help

you should use jquery ajax function either $.get, $.ajax, $.load, etc. here example.

js:

    <script>     $ = jquery;     $.ajax({       type: "post",       url: "your_code.php",       data: { prueba: "chihuahua" }     }).done(function(){       //do code     });     <script> 

php:

    <?php         $catname = $_post['prueba'];         echo $catname; // show correct pass js variable php variable         $posts = get_posts('category_name='.$catname);         foreach ($posts $post) {             echo "hola";         }     ?> 

hope helps. :)


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -