Fetch data from a WP page with same name as current username

According with docs, when you want to retrieve field attached to post using get_field / the_field you should pass a numeric ID as 2nd argument. You are passing a string. So your code should work if: $login = wp_get_current_user()->user_login; $page = $login ? get_page_by_path( $login ) : false; $field = $page ? get_field(‘my_custom_field’, $page->ID) : … Read more

If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?

For all intents and purposes, you only need one loop. While s_ha_dum’s comment is correct, odds are since you’re asking this question, you won’t have a need for multiple loops. <? get_header(); ?> <? if(have_posts()): while(have_posts()): the_post(); ?> <!–Your content here, like so–> <div id=”content”> <? the_field(‘body_content’); ?> <? the_field(‘footer_content’); ?> </div> <? endwhile; endif; … Read more

How to query the content of a specific custom post type?

On your custom post type’s single page, you want to treat it similar to your standard post single template. For the most part, you should wrap everything in your single template in one loop like so: <? get_header(); ?> <? if(have_posts()): while(have_posts()): the_post(); ?> <!–Your content goes here–> <? endwhile; endif; ?> <? get_footer(); ?> … Read more

How to Order Posts by Custom Fields?

var_dump your $args arguments: array(4) { [“cat”]=> string(7) “2,39,30” [“orderby”]=> string(14) “meta_value_num” [“order”]=> string(4) “DESC” [“meta_key”]=> string(12) “album_rating” } The second time you use a key, you overwrite the first time. You cannot build the array like that. The orderby parameter will take a space separated string, so this is closer: $args = array( ‘cat’ … Read more

Time sort with meta_key using UNIX timestamp failing due to date differences

I will caveat this by saying that I am still not 100% sure I know what you are doing, but I believe the following will sort your results by time only assuming that your meta values are proper Unix timestamps. function orderby_time_only($orderby) { remove_action(‘posts_orderby’,’orderby_time_only’); return preg_replace(‘|(.*)\s(.*)|’,’DATE_FORMAT(FROM_UNIXTIME($1),”%k%i”) $2′,$orderby); } add_filter(‘posts_orderby’,’orderby_time_only’); $args = array( ‘post_type’ => ‘event’, … Read more

Can’t see custom field after the Loop [closed]

When you output your get_posts results and do this: setup_postdata($post); You overwrite the original value of $post which the_field uses to fetch the field data. It’s trying to get that field belonging to the last post in $products_mono_posts instead of the page that the field actually belongs to. After running custom queries where the value … Read more