How to get custom post type to display post meta on archive pages?
Just change, <?php if ( ‘post’ === get_post_type() ) codilight_meta_1();?> to <?php if ( ‘post’ === get_post_type() || ‘reviews’ === get_post_type()) codilight_meta_1();?>
Just change, <?php if ( ‘post’ === get_post_type() ) codilight_meta_1();?> to <?php if ( ‘post’ === get_post_type() || ‘reviews’ === get_post_type()) codilight_meta_1();?>
You might try adding a second meta_query that would look for anything without the meta key: $args = array( ‘post_type’ => ‘agenda’, ‘paged’ => $paged, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘datum_event’, ‘value’ => date(‘Ymd’), ‘compare’ => ‘<=’ ), array( ‘key’ => ‘datum_event’, ‘meta_compare’ => ‘NOT_EXISTS’, ‘value’ => ‘placeholder’ ), ), ); … Read more
Once you’ve got the id of a post or page, use get_the_title($id) to get the page title (which is what I assume you mean by name) Codex Reference
Your meta field contains the ID of the attachment, you need to fetch that ID, then get the filename using that attachment ID. $doc_id = get_post_meta( get_the_ID(), ‘pdf’, true ); $filename = basename( get_attached_file( $doc_id ) ); echo $filename;
meta_id in postmeta table is just an AUTO_INCREMENT id for the table, you can easily inspect that: So, your guess is correct, you can leave it. EDIT Avoid raw SQL statements and introduce $wpdb for SQL purposes. And for postmeta insertion you can see the following tutorial I found a best one: Reusable Custom Meta … Read more
The reason you have a problem is 0 is also considered equal to false, when the get_post_meta call returns false, it’s also the same as being equal to 0. if( !get_post_meta( $post_id, ‘some-non-existant-field’, true ) == 0 ) Would be the same as … if( get_post_meta( $post_id, ‘some-existing-field’, true ) == 0 ) ..the only … Read more
The 404.php template file is used for 404 errors: i.e. no posts found. Since there are no posts, there is no $post object. With no $post object, functions such as the_ID() are not available, and will return the error you’re observing. The fix: replace all instances of $post-derived data with static data. e.g. replace this: … Read more
Check the action of the current screen object for add: function wpd_add_meta_box() { $screen = get_current_screen(); if( ‘add’ != $screen->action ){ add_meta_box( ‘myplugin_sectionid’, ‘My meta box’, ‘myplugin_meta_box_callback’, ‘leads’ ); } } add_action( ‘add_meta_boxes’, ‘wpd_add_meta_box’ );
The query value parameters can be set to true ( returns single result) or false ( an array). http://codex.wordpress.org/Function_Reference/get_post_meta For instance http://www.mattvarone.com/wordpress/query-multiple-meta-values/
If your posts page is a static page selected under Settings > Reading > Front page displays, then get_queried_object_id() will return the ID for that page which you can use to fetch meta data. $check_meta = get_post_meta( get_queried_object_id(), ‘checkbox’, true ); $header_meta = get_post_meta( get_queried_object_id(), ‘header’, true ); $textarea_meta = get_post_meta( get_queried_object_id(), ‘textarea’, true );