I want to run a shortcode using the [jobs]
on my PHP template. I'm using the WP Job Manager plugin. A sample code:
<?php
global $post;
$company_name = esc_attr(urldecode(get_query_var(apply_filters('wp_job_manager_companies_company_slug', 'company'))));
?>
<a href="#" onclick="test(); return false;"> test </a>
<span id="php_code"> </span>
<script type="text/javascript">
function test(){
phpTest = "<?php echo "json_encode(do_shortcode(\'\[jobs post_status='publish' keywords='" .$company_name. "'\]'));"; ?>";
document.getElementById("php_code").innerHTML = phpTest;
}
</script>
This outputs the actual text, but I want to actually run the do_shortcode()
function of WordPress so that it outputs whatever the [jobs]
shortcode does. Using <?php echo do_shortcode(params); ?>
on the template actually works. I'm creating a custom function using radio buttons.
Reference for code I found at the internet:
I want to run a shortcode using the [jobs]
on my PHP template. I'm using the WP Job Manager plugin. A sample code:
<?php
global $post;
$company_name = esc_attr(urldecode(get_query_var(apply_filters('wp_job_manager_companies_company_slug', 'company'))));
?>
<a href="#" onclick="test(); return false;"> test </a>
<span id="php_code"> </span>
<script type="text/javascript">
function test(){
phpTest = "<?php echo "json_encode(do_shortcode(\'\[jobs post_status='publish' keywords='" .$company_name. "'\]'));"; ?>";
document.getElementById("php_code").innerHTML = phpTest;
}
</script>
This outputs the actual text, but I want to actually run the do_shortcode()
function of WordPress so that it outputs whatever the [jobs]
shortcode does. Using <?php echo do_shortcode(params); ?>
on the template actually works. I'm creating a custom function using radio buttons.
Reference for code I found at the internet: https://www.daniweb.com/programming/web-development/threads/312161/php-innerhtml-and-blank-spaces
A simple google search led me to this: You can't run PHP with javascript. JavaScript is a client side technology (runs in the users browser) and PHP is a server side technology (run on the server). If you want to do this you have to make an ajax request to a PHP script and have that return the results you are looking for.