Support » Plugin: Insert PHP » Parse error: syntax error, unexpected T_VARIABLE in

  • Resolved grimerking

    (@grimerking)


    I’m trying to insert the following code into a post:

    <?php
    $my_id = 1149
    $post_id_1149 = get_post($my_id);
    $content = $post_id_1149->post_content;
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    echo $content;
    ?>

    So, I entered the following into the ‘text’ field:

    [insert_php]
    $my_id = 1149
    $post_id_1149 = get_post($my_id);
    $content = $post_id_1149->post_content;
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    echo $content;
    [/insert_php]

    The code is supposed to populate the ‘body text’ of the page with the contents of post_id_1149. The code is ‘good’ – i.e. if added to page.php it does what it is supposed to do. However, I’m trying to auto-populate the mobile version of the site using the content of the desktop version. That way, I only have to update the desktop version and the mobile version should automatically reflect any updates.

    Unfortunately, I’m getting the following error:

    Parse error: syntax error, unexpected T_VARIABLE in /.../plugins/insert-php/insert_php.php(48) : eval()’d code on line 3

    Am I doing something wrong?

    http://wordpress.org/plugins/insert-php/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author WillBontrager

    (@willbontrager)

    Hi grimerking,

    It’s a common misconception and I’ll have to rewrite the instructions page to make it clearer.

    While Inert PHP is a plugin, it runs only PHP code that would run on a page independent of WordPress. In other words, it doesn’t have access to WordPress-specific functions.

    Thus, neither get_post() nor apply_filters() will run within Insert PHP.

    An independent MySQL connection with PHP mysqli…() functions to retrieve the content of certain tables should work. You may need to write your own filter function as a substitute to apply_filters().

    Putting the PHP code into a separate web page and running it in the browser may be easier than debugging with the Insert PHP plugin. The error messages are likely to be more pertinent. After it runs independently, it should run OK with the Insert PHP plugin.

    Will

    Hi Will,

    Thanks for taking the time to provide support.

    To be honest, that solution is beyond my skill-set at the moment – maybe something I’ll come back to in a few months time.

    Rob

    Plugin Author WillBontrager

    (@willbontrager)

    Gratuitous post to mark thread resolved.

    Plugin Author WillBontrager

    (@willbontrager)

    Gratuitous post to mark thread resolved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Parse error: syntax error, unexpected T_VARIABLE in’ is closed to new replies.