Get Post Primary Category

Here you go. Add this to functions.php and call it from anywhere you want. function get_post_primary_category($post_id, $term=’category’, $return_all_categories=false){ $return = array(); if (class_exists(‘WPSEO_Primary_Term’)){ // Show Primary category by Yoast if it is enabled & set $wpseo_primary_term = new WPSEO_Primary_Term( $term, $post_id ); $primary_term = get_term($wpseo_primary_term->get_primary_term()); if (!is_wp_error($primary_term)){ $return[‘primary_category’] = $primary_term; } } if (empty($return[‘primary_category’]) || … Read more

Unable to show meta box data in frontend

You should be able to display the data mentioned in your question. // use within loop echo get_post_meta( $post -> ID, ‘_listing_overview_content_key’, true ); Example: /** * Setup query to show the ‘car_listing’ post type with ‘8’ posts. * Output is title with excerpt, Listing Overview, Fuel Type an Listing Category. */ $args = array( … Read more

how to add extra GET parameters to post to url with add_rewrite_rule?

You want to use the add_rewrite_endpoint since what you are concerned with is at the end of the URL. function wpseo331941_reader_endpoint() { add_rewrite_endpoint(‘readers’, EP_PERMALINK | EP_PAGES); } add_action(‘init’, ‘wpseo331941_reader_endpoint’, 10, 0); //When you want to check if the ‘readers’ is being used if ( false !== get_query_var(‘readers’, false) ){ //…. } Note that the false … Read more

Custom post type show on both Home and Date Archive

In your code ( $query->is_home() && $query->is_date() && $query->is_main_query() ) always returns false because $query->is_home() and $query->is_date() cannot be true on same page. Try this, function add_custom_post_type_to_query( $query ) { if ( ! is_admin() && $query->is_main_query() ) { if ( $query->is_date() || $query->is_home() ) { $query->set( ‘post_type’, array(‘post’, ‘pictures’) ); } } } add_action( ‘pre_get_posts’, … Read more

Get all Posts If has same custom field values in Posts

Following code will be proper for the meta query. $query_args = array( ‘post_type’ => ‘service’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘value’ => $zip, ‘compare’ => ‘LIKE’, ‘key’ => ‘zipcode’, ), ) ); $query = new WP_Query($query_args); <?php if ( $query->have_posts() ) :while ( $query->have_posts() ) : $query->the_post(); ?> <h3><?php the_title(); ?></h3> <?php endwhile; … Read more

“add_post_type_support” with Custom Post Type & ACF

You need to use filters to hook into manage_posts_columns and manage_posts_custom_column which will let you add the table heading and dates. The filters are slightly special as you need to include the name of your custom post type manage_{$post_type}_posts_columns manage_{$post_type}_posts_custom_column where {$post_type} in your case is conferences // Add the table heading function conf_columns_head($defaults) { … Read more