• Resolved mariostella

    (@mariostella)


    Hi,

    I am using all in one seo pack and trying to have one of my custom fields inserted in the meta title generated by all in one seo pack.
    I am writing a plugin that does this, but am getting stuck with the SQL query part.

    Any ideas? Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter mariostella

    (@mariostella)

    Thank you, this will get me somewhere!

    Thread Starter mariostella

    (@mariostella)

    I tried as written in the thread suggested and modified the plugin to include the SQL query

    function sample_function() {
    	global $post;
    	$id = $post->ID;
    	$town = get_post_meta($id, 'test', true);
    	if ($town != '') {
    	echo $town;}
    	}

    but it does not work at all.

    This is the first plugin I am writing and I seem to be missing some vital part.

    <?php
    /*
    Description: Posts the town to the meta title
     */
    if (!class_exists("ThriftyPlugin")) {
    	class ThriftyPlugin {
    		function ThriftyPlugin() { //constructor
    
    		}
    		function addHeaderCode() {
    			?>
    <!-- Some test comment in the DOM -->
    			<?php
    
    		}
    		function addContent($content = '') {
    			$content .= "Some test content at end post
    ";
    			return $content;
    		}
    		function authorUpperCase($author = '') {
    			return strtoupper($author);
    		}
          function sample_function() {
    	global $post;
    	$id = $post->ID;
    	$town = get_post_meta($id, 'test', true);
    	if ($town != '') {
    	echo $town;}
    	}
    
    	}
    
    } //End Class ThriftyPlugin
    
    if (class_exists("ThriftyPlugin")) {
    	$dl_PostToTitle = new ThriftyPlugin();
    }
    //Actions and Filters
    if (isset($dl_PostToTitle)) {
    	//Actions
    	add_action('wp_head', array(&$dl_PostToTitle, 'addHeaderCode'), 1);
    	//Filters
    	add_filter('the_content', array(&$dl_PostToTitle, 'addContent'));
    	add_filter('get_comment_author', array(&$dl_PostToTitle, 'authorUpperCase'));
    }
    ?>

    I have no idea how to hook the sample_function to make it work. I then need to make the content written within the <title></title> tags, but I’ll discover that later.
    Any help on how to get the content echoed?

    Thread Starter mariostella

    (@mariostella)

    I am not going forward with this. I tried including the function with the following sql query:

    function sample_function() {
    		global $wpdb;
    		$wpdb->query("
    		UPDATE $wpdb->postmeta WHERE meta_key = 'test'");

    But to no use. Also, what is the correct filter I should associate with this function? Any ideas anyone? HELP PLEASE!!

    Thread Starter mariostella

    (@mariostella)

    Ok I solved this the following way:

    function post_the_meta() {
    	global $wp_query;
    	if ( is_single() ) {
    		if ( $wp_query->post ) {
    			$post = $wp_query->post;
    			if ( get_post_meta( $post->ID, '$key', true ) ) {
    				echo get_post_meta( $post->ID, '$key', true ) . "\n";
    			}
    		}
    	}
    }

    Thanks to John Blackbourn and his Head Meta plugin

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Write SQL query to grab a custom field and insert it in the post meta title’ is closed to new replies.