Meta boxes not saving

I believe the issue is this line: if( $post->post_type == ‘startups’ ) return; Won’t your custom posts always have the type startups? Basically you are telling your code that whenever I save my custom post type, ignore my custom fields. You probably meant to have one of the WP reserved types (e.g. revision or attachment) … Read more

Related posts not working in the index

That code should work. I just tested in my own index.php and it worked. Are you sure you’re looking at the index.php file. Sometimes WP actually pulls a different template: For more info, see WP template hierarchy diagram. To test what template you’re seeing, place this code in your functions.php file temporarily: add_action(‘wp_head’, ‘show_template’); function … Read more

How to retrieve custom field values and save again as array

This is how I would do it… $page_list = get_pages(); foreach($page_list as $page) { $post_id = $page->ID; $custArray = array( ‘_custField1’ => get_post_meta( $post_id, ‘_custField1’, true ), ‘_custField2’ => get_post_meta( $post_id, ‘_custField2’, true ), ‘_custField3’ => get_post_meta( $post_id, ‘_custField3’, true ), ‘_custField4’ => get_post_meta( $post_id, ‘_custField4’, true ) ); add_post_meta ( $post_id, ‘_newcust’, $custArray, true … Read more

Alternating Post Styles on Homepage

You can add custom classes to each post. Here is a quick example of one approach: add_action(‘post_class’,’YOURNAME_post_class’); function YOURNAME_post_class( $classes ) { global $wp_query; if( ! $wp_query->is_main_query() ) return $classes; $classes[] = ‘class-on-all-posts’; if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % 3 ) $classes[] = ‘class-on-every-third-post’; if( 0 == $wp_query->current_post || 0 == $wp_query->current_post … Read more

How to create a Top 10 Popular Posts Page?

Here’s a start (Function found here); function getPostViews($postID){ $count_key = ‘post_views_count’; $count = get_post_meta($postID, $count_key, true); if($count==”){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, ‘0’); return “0 View”; } return $count.’ Views’; } function setPostViews($postID) { $count_key = ‘post_views_count’; $count = get_post_meta($postID, $count_key, true); if($count==”){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, ‘0’); }else{ $count++; update_post_meta($postID, $count_key, $count); … Read more

Post Format problem

What about add else { after get_template_part( ‘template-parts/content’, ‘video’); }? EDIT (1) : <?php /** * The template for displaying single posts. * * @package SN */ get_header(); ?> <?php while ( have_posts() ) : the_post(); ?> <?php if( has_post_format(‘video’)) { get_template_part( ‘template-parts/content’, ‘video’); }else{ ?> <div id=”content-wrapper”> <div id=”primary” class=”content-area”> <main id=”main” class=”site-main” role=”main”> … Read more

Edit Posts Page but not category specific pages?

You can create a Page template in which display all posts with your custom markup. <?php /** * Template Name: My Custom Blog * */ // The Query $args = array(‘posts_per_page’=>-1); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo ‘<ul>’; while ( $the_query->have_posts() ) { $the_query->the_post(); echo ‘<li>’ … Read more