WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Meta data for Custom Post Types / * HELP */ (4 posts)

  1. alhadis
    Member
    Posted 4 years ago #

    Okay, so... I've fallen into a logjam. I'm using a Custom Post type of "Publication" for a client who publishes books, and I need a widget to display a reel of recently added publications on the front page. Now, the text displayed in each publication is being drawn from meta data stored with the post... which works fine in the Admin Panel, but for some reason, calling get_post_meta() or get_metadata() from the Loop doesn't return any values but the usual "_edit_lock", "_edit_last".

    I feel I've tried everything, and I'm at a loss. :\ If get_post_custom() is retrieving meta data perfectly fine from the database in the Admin end, then why the bloody hell isn't it doing the same in the Loop??? D:

    Oh yeah, here's the code for the Publication post type:

    /*	Array of Labels used for Custom Post Type	*/
    $labels	=	array(
    	"name"				=>	__('Publications'),
    	"singular_name"			=>	__('Publication'),
    	"add_new"			=>	_x('Add New', 'publication'),
    	"add_new_item"			=>	__('Add New Publication'),
    	"edit_item"			=>	__('Edit Publication'),
    	"new_item"			=>	__('New Publication'),
    	"view_item"			=>	__('View Publication'),
    	"search_items"			=>	__('Search Publications'),
    	"not_found"			=>	__('No Publications Found'),
    	"not_found_in_trash"		=>	__('No Deleted Publications Found'),
    	"parent_item"			=>	__('Parent Publication')
    );
    
    $args	=	array(
    	"labels"			=>	$labels,
    	"public"			=>	true,
    	"show_ui"			=>	true,
    	"menu_icon"			=>	get_bloginfo("template_directory") . "/img/publication.png",
    	"menu_position"			=>	20,
    	"capability_type"		=>	"post",
    	"hierarchical"			=>	false,
    	"taxonomies"			=>	array("writer"),
    	"rewrite"			=>	array("slug" => "publication"),
    	"supports"			=>	array("title", "editor", "thumbnail", "excerpt", "trackbacks", "comments", "revisions"),
    	"register_meta_box_cb"		=>	"publication_meta_boxes"
    );
    register_post_type("publication", $args);

    There's a deadline on this... :( S.O.S

  2. alhadis
    Member
    Posted 4 years ago #

    Actually, scratch the bit about it being stored in the Admin menu, I think it had something to do with the form values being held in my browser after submitting the page (because when I left, they'd gone blank again after I returned.)

  3. chinmoy
    Member
    Posted 4 years ago #

    I think that in supports section you miss the 'custom-fields'.

    "supports"			=>	array("title", "editor", "thumbnail", "excerpt", "custom-fields", "trackbacks", "comments", "revisions")

    Write this once and add the content in the custom fields. Then use the get_post_meta() function to retrieve the data.

  4. alhadis
    Member
    Posted 4 years ago #

    Actually, that had no bearing on the ability to store or retrieve meta-data. All it did was add a metabox for users to manage the custom fields themselves.

    It's working now, but... I'm not sure how. For lack of anything better, I explicitly set "query_var" to the post type's name ("publication"), and I suddenly noticed the metadata was being written to the database properly. Logically, that shouldn't have had any influence if the default value of "query_var" is to use the post type's name, but... *shrug* Meh, whatever works... :\

Topic Closed

This topic has been closed to new replies.

About this Topic