List all native posts in template page?

There is nothing wrong in your query, but there is some code (a plugin?) that remove from results the posts in the category having term id 1 or 4. (Normally category with term id 1 is ‘uncategorized’) You can notice that looking at request performed AND ( wp_posts.ID NOT IN ( SELECT object_id FROM wp_term_relationships … Read more

post type slug vs page slug

You can created a post template to display the CPT post details (i.e. videos/my-video) and you can create an archive template to display a list of posts (i.e. videos/). To create a post template in a plugin, add the following to the plugin: function include_templates( $template_path ) { if ( get_post_type() == ‘videos’ ) { … Read more

Optimize CPT-function with a loop

Finally I got the solution. One of the major problems was the usage of “get_post_custom” for fetching the database. I used “get_post_meta” instead and it was a lot easier to work with the array that was created by that function. I am sure that it would have been possible to do it with the first … Read more

Rand post related question

This is more a generic PHP question, but for what it’s worth: if ( empty( $_SESSION[‘seed_time’] ) ) $_SESSION[‘seed_time’] = time(); if ( empty( $_SESSION[‘seed’] ) || time() > ( $_SESSION[‘seed_time’] + 30 * MINUTE_IN_SECONDS ) ) { // Seed session is empty, or session time is older than 30 minutes, generate new seed $_SESSION[‘seed’] … Read more

WordPress query portfolio posts

You can simply just add the cat or category_name parameter to your query. When using cat, you should use the category ID, and should you use category_name, it should be the slug of the category, not the name. Change <?php $tarali_query = new WP_Query(‘posts_per_page=”.$nbmax.”&ignore_sticky_posts=1&paged=’.$paged); ?> to <?php $tarali_query = new WP_Query(‘posts_per_page=”.$nbmax.”&cat=CATID&ignore_sticky_posts=1&paged=’.$paged); ?> For futher reading: … Read more

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); ?>