WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: Get A Post] no longer working in WP3.0 (5 posts)

  1. Paul Jarvis
    Member
    Posted 4 years ago #

    one of my most used (and simple) plugins seems to not work in the newest version of wordpress. it's a simple plugin, so here's the source below. does anyone know what about it making the newest wordpress not be able to use it properly?

    function get_a_post($id) {
    	global $post, $tableposts, $wp_version, $wpdb;
    	$now = current_time('mysql');
    
    	if($id) {
    		if(is_numeric($id)) {
    			$name_or_id = 'ID';
    		} else {
    			$name_or_id = 'post_name';
    		}
    
    		$post = $wpdb->get_row("SELECT * FROM $tableposts WHERE (post_status = 'publish' OR post_status = 'static') AND post_date <= '$now' AND $name_or_id = '$id'");
    		get_post_custom($post->ID);
    		if(preg_match("/^1.2/",$wp_version)) {
    			start_wp();
    		} else {
    			setup_postdata($post);
    		}
    	}
    }
  2. Hax
    Member
    Posted 4 years ago #

    I have not test it but one thing jumps out.

    instead of using "$tableposts" on your query use $wpdb->posts like so "SELECT * FROM $wpdb->posts WHERE (post_status = 'publish' OR post_status = 'static') AND post_date <= '$now' AND $name_or_id = '$id'"

  3. Paul Jarvis
    Member
    Posted 4 years ago #

    that worked! thank you so much, cheers.

  4. sayumi
    Member
    Posted 4 years ago #

    hey twothirty,
    could you provide the whole source code of the plugin? because i'd like to use it as well but i cant seem to get it to work :(
    i already copied the whole code you got above, but it didnt work
    thanks a bunch!

  5. Paul Jarvis
    Member
    Posted 3 years ago #

    sure thing, here's the full code:

    <?php
    /*
    Plugin Name: Get-a-Post
    Plugin URI: http://guff.szub.net/get-a-post
    Description: Display a specific post (or Page) with standard template tags.
    Version: R1.1
    Author: Kaf Oseo
    Author URI: http://szub.net
    
    	Copyright (c) 2004, 2005, Kaf Oseo (http://szub.net)
    	Get-a-Post is released under the GPL license
    	http://www.gnu.org/licenses/gpl.txt
    
    	This is a WordPress plugin (http://wordpress.org).
    
    	WordPress is free software; you can redistribute it and/or modify
    	it under the terms of the GNU General Public License as published
    	by the Free Software Foundation; either version 2 of the License,
    	or (at your option) any later version.
    
    	This program is distributed in the hope that it will be useful,
    	but WITHOUT ANY WARRANTY; without even the implied warranty of
    	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    	General Public License for more details.
    
    	For a copy of the GNU General Public License, write to:
    
    	Free Software Foundation, Inc.
    	59 Temple Place, Suite 330
    	Boston, MA  02111-1307
    	USA
    
    	You can also view a copy of the HTML version of the GNU General
    	Public License at http://www.gnu.org/copyleft/gpl.html
    
    */
    
    function get_a_post($id) {
    	global $post, $wp_version, $wpdb;
    	$now = current_time('mysql');
    
    	if($id) {
    		if(is_numeric($id)) {
    			$name_or_id = 'ID';
    		} else {
    			$name_or_id = 'post_name';
    		}
    
    		$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE (post_status = 'publish' OR post_status = 'static') AND post_date <= '$now' AND $name_or_id = '$id'");
    		get_post_custom($post->ID);
    		if(preg_match("/^1.2/",$wp_version)) {
    			start_wp();
    		} else {
    			setup_postdata($post);
    		}
    	}
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic