WordPress.org

Ready to get started?Download WordPress

Forums

Insert PHP
[resolved] Parse error: syntax error, unexpected T_VARIABLE in (5 posts)

  1. grimerking
    Member
    Posted 9 months ago #

    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/

  2. WillBontrager
    Member
    Plugin Author

    Posted 9 months ago #

    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

  3. grimerking
    Member
    Posted 9 months ago #

    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

  4. WillBontrager
    Member
    Plugin Author

    Posted 9 months ago #

    Gratuitous post to mark thread resolved.

  5. WillBontrager
    Member
    Plugin Author

    Posted 9 months ago #

    Gratuitous post to mark thread resolved.

Reply

You must log in to post.

About this Plugin

About this Topic