Why does my WPDB enquiry on test server work but not on the live server? (5 posts)

  1. mirefoot
    Posted 2 years ago #

    I am using wordpress to output some ads on a non wordpress page. The HTML on the non wordpress test server page is:

        echo init_ads();

    On my Test server I have this code in the functions file and the post type is a custom post type I have created call manufacturer:

    function init_Ads() {
        echo $_SERVER['DOCUMENT_ROOT'];
    	$serial = $_GET["serial"];
    			// args for query
    			$args = array(
    				'numberposts' => -1,
    				'post_type' => 'manufacturer',
    				'meta_key' => 'smashing_post_class',
    				'meta_value' => $serial
        $the_query = new WP_Query( $args );
        $meta= get_post_meta( get_the_ID(), 'ad_rotator_group', TRUE); 
        wp_reset_query();  // Restore global post data stomped by the_post().
    	echo adrotate_group($meta);

    And on the test URL http://www.m1creative.org/noword/index.php?serial=57 it works.
    I am passing in a number 'serial' and extracting its corresponding ad group which then displays the correct ads on the page. Use serial = 57 to get a valid ad group.

    On the live server page: https://www.partslocator.com.au/adsrotator/testnoword.php?serial=57 it doesn't work.

    This is the HTML of the live server non wordpress page:

        echo init_ads();

    If I change the echo adrotate_group($meta); to echo adrotate_group(1); I get the correct result and the ads display.

    I am not using the loop in the query as there is only ever going to be one result.

    Is the https causing me problems or is there something else I haven't spotted?

  2. mirefoot
    Posted 2 years ago #

    Any help would be much appreciated

  3. catacaustic
    very awesome
    Posted 2 years ago #

    If that's what's happening, then the value that's set for $meta is either different on the live server, or is set, but is set for a different post.

    This is where some basic debugging comes into it. You will need ot see what the value that you get for $meta is on both systems, and if it's not the same (I'm betting that it's not) work backwards through the code to see what else is different and where the differences come from. When you find that you should be able to answer your own problem.

  4. mirefoot
    Posted 2 years ago #

    Thanks, but $meta is NULL in the live site as far as I can tell, so no return is coming from WPDB

  5. catacaustic
    very awesome
    Posted 2 years ago #

    So... as I said before, work backwards and see what is happening to make it NULL instead of whatever value you epxect it to be.

    Start with this line:

    $meta= get_post_meta( get_the_ID(), 'ad_rotator_group', TRUE);

    Make sure the values going in there are the same.

    If they are, move backwards checking everything until you get to the start of your function. Something will be different. You just need to figure out what it is.

Topic Closed

This topic has been closed to new replies.

About this Topic