• Aimee

    (@greatdanemaniac)


    Hi!
    I’m a total noob when it comes to certain things regarding WP. However, I’d really like to see some new features that would make my use of WP a dream.

    I’m trying to create a WP plugin that displays custom fields, without the need of any extra code in the loop. Can somebody please help me with this?

    I need a plugin for displaying data since I’m working on a site that needs data to be displayed easily.

    So far this is how my code looks:

    function post_meta_display($custom_fields) {
    
    	global $post;
    	$custom_fields = '';
    	$key = array();
    	$value = array();
    
    	$custom_fields = the_meta();
    }
    add_filter('the_content', 'post_meta_display');

    This seems to work with displaying the data, but it broke all the images from other posts. That’s why I need help. I don’t know a thing about how parameters work. The code above is inspired by the plugin “taxonomy terms list” and some stuff from the arras theme.

    Can somebody please help me in the right direction, please?

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • When you add to the_content it adds to the editor-window. I don’t think that’s what you want to do. It much easier to just add get_post_meta.

    Unfortunately you have to put it in the loop. May I ask you why you don’t wan’t any extra code?

    Thread Starter Aimee

    (@greatdanemaniac)

    Get post meta doesn’t work at all, I just get a bunch of error messages when I use that line of code.

    I want a plugin that displays either custom fields or taxonomies easily without touching any code and without relying on any theme. I know that there is a plugin called taxonomy terms list by Mfields, but it’s not that perfect as I want it. First of all it lacks the type of styling and you have to change the code in order for the terms and taxonomies to be displayed everywhere (archives, categoriy view etc.) not just in single post view.

    I’ve been thinking about custom fields for a while, they are so much easier when it comes to styling, but if I can’t create a plugin that displays the data in the post without adding a line of code into my theme, then it’s not possible for such a plugin to happen.

    The only thing that WP lacks is this, lack of displaying the most basic information in posts after the content itself.

    Thread Starter Aimee

    (@greatdanemaniac)

    I think I’ve might have solved the problem now, but there is one thing that remains a struggle.

    The custom field data is now placed above the content, but I want it to be displayed below it. This is how my code looks at the moment:

    function cf_display($content) {
    	global $post;
    
    	$postmeta = '';
    
    		$custom_fields_list = the_meta();
    
    	if ($custom_fields_list) {
    		foreach($custom_fields_list as $field_id => $field_name) {
    			if ( $field_value = get_post_meta($post->ID, $field_id, true) ) {
    				$postmeta .= '<div class="postmeta">';
    				$postmeta .= '<span class="field' . $field_id . '">' . $field_name . '</span>';
    				$postmeta .= '<span class="value' . $field_id . '-value">' . $field_value . '</span>';
    				$postmeta .= '</div>';
    			}
    		}
    	}
    
    	if ( get_option('post_meta') == 'bottom' ) return $postmeta . $content;
    	else return $content . $postmeta;
    }
    
    add_filter('the_content', 'cf_display');
    add_option('post_meta', 'bottom', $deprecated, 'yes');

    Can somebody please tell me how to get the data below the content?

    Thanks!

    Hi:

    Looking briefly at your code I think you simply need to modify your if/else statement. Currently if your post_meta option is equal to bottom you are pre-pending the $postmeta data when you should be appending it.

    if ( get_option('post_meta') == 'bottom' ) return $content . $postmeta;
    	else return $postmeta . $content;

    Thread Starter Aimee

    (@greatdanemaniac)

    Thanks for your reply.
    Although it didn’t work… seems that the post’s meta is above the content…

    Is there perhaps another way to make the code know it’s supposed to be put at the bottom of the post?

    Have you looked at add_shortcode? Just wrote a snippet that did exactly what I think you want using that. Sorry if I missunderstood the purpose, but I use it something like this (simplified):

    function thefunction() {
    	$mycustom = get_post_custom_values('somemeta');
    	foreach ( $mycustom as $key => $value ) {
    		$mystr.=$value;
    	}
    	return $mystr;
    }
    add_shortcode('thetag', 'thefunction');

    The you just put [thetag] whereever you want in your post and it gets printed right there.

    Thread Starter Aimee

    (@greatdanemaniac)

    Hmm… I’ve thought about that, using a shortcode. I’m not sure if I want to use it.

    For now I’ve just decided to put the_meta inside the loop and in the single.php file instead, until there is a solution for this.

    Thanks anyway for your help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Help with creating a custom field plugin’ is closed to new replies.