When WP_Query only returns 1 post, how do I automatically redirect to that post?

You can do this by checking the number of results returned by your query. Try this. <?php $rawfiltertag = get_post_meta( $post->ID, ‘_cmb_client_name’, true ); $filtertag = sanitize_title( $rawfiltertag ); // wp_query arguments $args = array ( ‘post_type’ => ‘post’, ‘meta_query’ => array( array( ‘key’ => ‘_cmb_client_target’, ‘value’ => $rawfiltertag ) ) ); // the query … Read more

Let Posts be stored in another table

Use save_post action hook as shown below but write custom insert/update queries to save information in a different table. add_action(‘save_post’, ‘save_product_data’); function save_product_data($post_id) { //verify nonce and all other code… $title = $_POST[‘post_title’]; //example variable $wpdb->query( $wpdb->prepare( ” INSERT into wp_product_instore ( post_id, meta_key, meta_value ) values ( $post_id, ‘post_title’, $title )” )); //likewise you … Read more

Issue with first top post display order

Your variable $postvariable in while loop skips, first post. Try this, <ul> <li>[widget id=”text-8″]</li> //short code to display sticky news <?php **//To display sticky on top** $paged = get_query_var( ‘paged’ ) ? get_query_var( ‘paged’ ) : 1; $sticky= get_option( ‘sticky_posts’ ); $args = array( ‘cat’ =>255, ‘ignore_sticky_posts’ => 1, ‘post__not_in’ => $sticky, //’paged’ => $paged, … Read more

wordpress add field to post_class

I would first store your field value in a variable after your loop just before the posts HTML tags start: <?php $size = the_field( “size” ); ?> And then add this variable to the post class function: <?php post_class($size); ?>

is it possible in a custom post, create custom fields as well whitin?

I think you’re looking for add_meta_box http://codex.wordpress.org/Function_Reference/add_meta_box // Metabox actions add_action( ‘add_meta_boxes’, ‘metabox_create’ ); // create add_action( ‘save_post’, ‘metabox_save’ ); // save // Create metabox function metabox_create() { add_meta_box( ‘metabox_name’, ‘Metabox Title’, ‘metabox_content’, ‘my_custom_post_type’, ‘normal’, ‘high’ ); } // metabox content function metabox_content() { global $post; // custom field data $custom = get_post_custom( $post->ID ); … Read more

Template for regular posts (no custom post types)

If you take a look at Template Hierarchy category-news.php would be archive template, that is for a list of multiple posts having specific category. There is no such thing as template for individual post, having specific category, in native template hierarchy. There are different ways to handle such, depending on your needs. Typical are: styling … Read more

Post Status Frontend Announcement

You can create an easy to use function to do that for you. Like so: <?php function sg_user_posts_by_type($userid, $post_status) { $args = array( ‘numberposts’ => -1, ‘post_status’ => array($post_status), ‘author’ => $userid ); $count_posts = count(get_posts($args)); return $count_posts; } if (is_user_logged_in()) { // GET CURRENT USER DATA $user_id = get_current_user_id(); $user_data = get_userdata($user_id); $publish_count = … Read more

How to edit the ‘

If i am not wrong then i think you are talking about this Blankslate theme. If this is the case then you can edit the older and newer links displayed on archive page by editing the following code by overwriting the theme file nav-below.php in the child theme. <div class=”nav-previous”><?php next_posts_link(sprintf( __( ‘%s older’, ‘blankslate’ … Read more

Hook Scripts and Styles in WordPress

You have two flaws in your code, one is a syntax error, the other one is the wrong hook. Firstly, wp_enqueue_scripts is the hook used to enqueue scripts and styles for front end use. When you need to enqueue scripts and styles for the backend, you should use the admin_enqueue_scripts hook Secondly, you are missing … Read more