Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Call to an undefined function???

  1. #1
    Jwrbloom is offline Hello World
    Join Date
    Feb 2010
    Posts
    28

    Default Call to an undefined function???

    Here is the error:
    Call to undefined function get_query_var()




    Here is the code I'm using:


    Code:
    <?php
    
    $playerName = get_query_var('the_title'); 
    
    var_dump($playerName);
    
    $con = mysql_connect("localhost","jwrbloom_","redcoach");
    
     mysql_select_db("jwrbloom_wpspselect", $con);	
    
    $query = 'SELECT * FROM team2011 ORDER BY uniform ASC';
    $results = mysql_query($query);
    
    while($line = mysql_fetch_assoc($results)) {
    
    	if ($playerName == $line['nameFirst'].'-'.$line['nameLast']) {
    
    	echo '<div>' . $line['nameFirst'].' '.$line['nameLast'] . '</div>';
    
    	}
    }
    ?>

  2. #2
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

  3. #3
    Jwrbloom is offline Hello World
    Join Date
    Feb 2010
    Posts
    28

    Default

    It's on a separate PHP file that I "include" on a Page, so when you go that Page it calls information from the datatable about the basketball player. From there, I'll add some things along the way. Right now, the 'echo' is just set up to test it.

    Here is the Page I'm testing it on:

    http://spieceselect.org/dwight-cliff/

    So all that is on that Page is:

    Code:
    <?php
    include("http://spieceselect.org/path-to-file/profile.php");
    ?>

  4. #4
    Rarst's Avatar
    Rarst is offline Big Tipper
    Join Date
    Jul 2009
    Posts
    322

    Default

    Interesting, that function is defined in query.php and it should always load.

    Also 'the_title' doesn't seem to be valid field in $wp_query, how did you came to this code?

    Try get_the_title() instead.

    PS I hadn't messed with pages much, but here is an idea - instead of including try placing your code in page template http://codex.wordpress.org/Pages#Page_Templates
    Last edited by Rarst; 03-13-2010 at 06:17 AM.
    Rarst.net - cynical thoughts on software and web (and sometimes WP) | @Rarst | I seem to be non-GPL-compliant person. Beware my poisonous thoughts.

  5. #5
    itsananderson's Avatar
    itsananderson is offline Big Tipper
    Join Date
    Jan 2009
    Location
    Terre Haute, IN
    Posts
    354

    Default

    The problem is that you're including the file via a web address which is basically using PHP's automagical http wrapper to make a new request to that file. Since it's a new request, query.php isn't being included so that function won't be defined. I'd suggest doing what Rarst said and just put the code in a page template, but if you MUST include the file, use this code instead.

    Code:
    <?php
    include(ABSPATH . 'path-to-file/profile.php');
    ?>
    That way the function will be defined (because you won't be generating a new request). It's almost always better to include a file via its file path rather than its URL. Not only do you not run into issues like this, but its also MUCH faster.

  6. #6
    Rarst's Avatar
    Rarst is offline Big Tipper
    Join Date
    Jul 2009
    Posts
    322

    Default

    Ouch, I managed to completely overlook http part in that include. :) Working on Saturday harms brain greatly. Guess I was lucky to still give adequate advice.
    Rarst.net - cynical thoughts on software and web (and sometimes WP) | @Rarst | I seem to be non-GPL-compliant person. Beware my poisonous thoughts.

  7. #7
    Jwrbloom is offline Hello World
    Join Date
    Feb 2010
    Posts
    28

    Default

    Only have time to respond, not work on it, but I will try it for sure. The reason for not putting it in the page template itself is I don't want it on certain pages. I guess I could create a separate template, but that's kind of what I'm doing here, hijacking it a little.

    My production site has many includes, and they worked flawlessly. I'm using the same code structure. $variable = get_query_var or some other WordPress template codex, followed by a query to my own data table within my WP database, then echo'ing the results that match the get_query_var.

    The main difference is those are dealing with archive pages, which draw from posts, and those appear to have more template tag support.

    I'll definitely try the abspath option.

  8. #8
    Jwrbloom is offline Hello World
    Join Date
    Feb 2010
    Posts
    28

    Default

    Ok...tried it after all. Got this error:

    Warning: include(/home/jwrbloom/public_html/spieceselect.org/resources/profile.php) [function.include]: failed to open stream: No such file or directory in /home/jwrbloom/public_html/spieceselect.org/wp-content/plugins/php_execution/includes/class.php_execution.php(270) : eval()’d code on line 2 Warning: include() [function.include]: Failed opening ‘/home/jwrbloom/public_html/spieceselect.org/resources/profile.php’ for inclusion (include_path=&#

  9. #9
    itsananderson's Avatar
    itsananderson is offline Big Tipper
    Join Date
    Jan 2009
    Location
    Terre Haute, IN
    Posts
    354

    Default

    Your include code?

  10. #10
    DD32 is offline Hello World
    Join Date
    Jul 2009
    Posts
    39

    Default

    In this case, I think you'd be much better off using a Page Template rather than using a PHP-exec type plugin.


    Info on page templates: http://codex.wordpress.org/Pages#Page_Templates

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •