Calling custom fields for pages (not posts)

try using get_metadata(‘post’, $postid, ‘teaser-text, true); these two actually same. should not make any difference. earlier i gave wrong arguments. var_dump() will show you what it is actually getting. please make sure, the ID is correct, ‘teaser-text’ exists. You can also try using some other meta name (for testing purpose only).

query user display_name failed in a custom mysql query foreach

You should use all of the goodness of the wpdb object. #Create a new WPDB object for your custom DB $foo_db = new wpdb(‘username’,’password’,’database’,’localhost’); $query = (‘SELECT * FROM custom_table’); #Use the get_results method – You can return OBJECT(default), OBJECT_K, ARRAY_A, ARRAY_N $results = $foo_db->get_results($query, OBJECT); foreach($results as $row){ $user = new WP_User($row->user_id); } You … Read more

Alternating post layout

minimal necessary correction – move the_post(); to before the if(($i%2 == 0) : for instance: <?php if (have_posts()) : while(have_posts()) : the_post(); $i++; if(($i % 2) == 0) : ?>

Get titles of all posts with current tags except current post

First things first, you have a syntax error: $page_title = the_title(); The the_title() template tag echoes, rather than returns, the post title. You will want to use get_the_title() instead: $page_title = get_the_title(); Second, you can simplify things considerably, simply by excluding the current post from your secondary query, by passing the post__not_in post parameter to … Read more

Custom Post Type Taxonomies -Posts not showing in Category or Tag pages

You were close with the code you posted in your comment. The issue is that you only tested for is_main_query, which will limit every query on your site to that single post type. function wpa82763_custom_type_in_categories( $query ) { if ( $query->is_main_query() && ( $query->is_category() || $query->is_tag() ) ) { $query->set( ‘post_type’, array( ‘post’, ‘resource’ ) … Read more

wordpress change the loop order by dynamic value

At the moment you publish/update the post with recommended price, it’s better to have another custom meta post to save the real price in it by using add_action() and add_post_meta(), then you can use the query you posted but with $query_args[‘meta_key’] = ‘real_price’; Something like below: function wp_po54785( $post_id ) { $recommended_price = get_post_meta( $post_id, … Read more

Upcoming Event: How do I sort database by custom date field, but ignore past dates?

You’re pretty close, but I wouldn’t be distracted by the ‘scope’ meta key. The following is untested. <?php $args = array( ‘post__not_in’ => array($donotrepeat), “post_type” => ‘event’, ‘meta_key’ => ‘_event_start_date’, // name of custom field ‘orderby’ => ‘meta_value’, “order” => ‘ASC’, “posts_per_page” => 1, ‘meta_query’ => array( array( ‘key’ => ‘_event_start_date’, ‘value’ => date(‘Y-m-d’), ‘compare’ … Read more