2

I'm trying to make a Wordpress plugin for my blog that scans for posts that contain the custom field _videoembed. I've got everything made and it activates correctly but I receive a PHP error when I open up a page to test it out:

Fatal error: Call to a member function get_results() on a non-object in .../wp-content/plugins/youtubesubscription/videos.php on line 26.

Does anyone know enough about PHP to help me out? Here's my plugin code (pasted on pastebin because of size): http://pastebin.com/uaEWjTn2

EDIT 1

I'm no longer getting any errors after inserting global $wpdb; but now nothing's showing up. Here's my updated code: http://pastebin.com/R2ZuEknY. Note, this code also incorporates auto YouTube thumbnails, which were obtained from a function that trims YouTube URLs to the IDs (link).

EDIT 2

Got it working, turns out all I needed to do was insert '_videoembed' as the 'meta_key' argument for a wp_query. Here's my working code below:

<?php
    $args = array(
        'meta_key' => '_videoembed',
        'post_status'     => 'publish',
        'posts_per_page'    => '' . $number . '',
        'order'    => 'date'
    );
    query_posts( $args );

    while ( have_posts() ) : the_post(); ?>
        <?php 
        global $post;
        $VIDEOID = ytvideoID($post->ID); 
        ?>
        <li onClick="window.location.href='<?php the_permalink(); ?>'">

            <?php
                global $post;
                $videoId = ytvideoID($post->ID);
                $videoInfo = parseVideoEntry($videoId);
                echo '<a href="'.get_permalink().'">';
                    echo '<div class="image">';
                        echo '<img src="http://img.youtube.com/vi/'.$VIDEOID.'/default.jpg">';
                        echo '<div id="time" style="position:absolute;z-index:9;bottom:2px;right:2px;font-size:10px;color:#fff;background:#000;padding:0px 2px;-webkit-border-radius: 4px;-moz-border-radius: 4px;border-radius: 4px;opacity:0.75;">'.hms($videoInfo->length).'</div>';
                    echo '</div>';
                echo '<h4>'.get_the_title().'</h4>';
                echo '<div id="description">';
                    echo '<div id"views"><h3>'.number_format($videoInfo->viewCount).' Views</h3></div>';
                    echo '<div class="singleauthor"><h3>by '.$videoInfo->author.'</h3></div>';
                echo '</div>';
                echo '</a>';
            ?>
        </li>
    <?php endwhile;

    // Reset Query
    wp_reset_query();

    ?>
1
  • Please refrain from adding the solution to the question by editing it. Rather add the solution below as answer to the post, even if it's your own post. Commented Apr 24, 2024 at 10:26

3 Answers 3

4

you get the post by custom field using the meta_query.

 $args= array(
    'category_name' => 'courses',
    'orderby'       => 'menu_order',
    'order'         => 'ASC',
    'meta_query' => array(
        array(
            'key'     => 'front_page',
            'value'   => 'yes',
            'compare' => 'LIKE',
        ))

);

$the_query = new WP_Query( $args );
Sign up to request clarification or add additional context in comments.

Comments

1

You'll have to to add global $wpdb;

try replacing

function mbrecentvids()
{ ?>
<?php

with

function mbrecentvids()
{
    global $wpdb;

4 Comments

Still no luck. I'm not getting any errors, but nothing's showing up. Here's my updated code: pastebin.com/R2ZuEknY
Now it's probably your query then, have you tried running it in mysql or phpmyadmin? Try adding echo's to your code to see wether it's reached
Hmm, I have it setup standalone in my footer but I'd wanted to make a widget out of it. It runs fine when it's planted down there but not in the widget.
You could try adding error_reporting(E_ALL); at the top of your code to see if there are any supressed errors
0

It looks like you're missing a semi-colon on line 26.

I see:
$pageposts = $wpdb->get_results($querydetails, OBJECT_K)

1 Comment

Thanks for the quick response. I tried adding a semicolon but I'm still getting an error for a call to a non-object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.