Querying, storing, and using data from 2 separate custom post types

For custom field queries you can’t use an array for multiple keys, unfortunately. What you want is something like this: $args = array( ‘post_type’ => array(‘gym_location’, ‘gym_term’), ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, ‘meta_query’ => array( array( ‘key’ => ‘term_active’, ‘value’ => ‘1’, ‘compare’ => ‘==’ ), array( ‘key’ => ‘location_active’, ‘value’ => ‘1’, ‘compare’ … Read more

Include template if a post is a single product

As Andy mentioned, you’re calling WCS_DIR, but that doesn’t exist. Updated the code to call WCT_DIR instead: define( ‘WCT_DIR’, plugin_dir_path( __FILE__ ) ); add_filter( ‘template_include’, ‘wdm_load_template’, 99 ); function wdm_load_template( $template ) { $template_slug = basename( rtrim( $template, ‘.php’ ) ); if ( ($template_slug === ‘single-product’ || $template_slug === ‘woocommerce’) && is_product() ) { $template … Read more

wp_query return nothing

You need to reference to your query, when starting the loop, otherwise it will show the posts found with the main query, instead of your custom query. Try: <?php $args = array( ‘post_type’=>’book’); $loop = new WP_Query( $args ); // Start the loop for your custom query if($loop->have_posts() ) : while ($loop->have_posts() ) : $loop->the_post(); … Read more

Custom Post Type Rewrite – Page Not Found

If you are using this in a plugin, from the codex: To get permalinks to work when you activate the plugin use the following example, paying attention to how my_cpt_init is called in the register_activation_hook callback: add_action( ‘init’, ‘my_cpt_init’ ); function my_cpt_init() { register_post_type( … ); } function my_rewrite_flush() { // First, we “add” the … Read more

Submitting custom post from frontend,jQuery ajax, and custom validation – can’t find proper place to insert wp_insert_post()

You can achieve the goal through many ways. though the way you have selected is not an appropriate one but you can go with it also. just include the file wp-blog-header.php file (placed at the wordpress root) into validation.php above all other code. you can find all the wordpress related functions will work like a … Read more

Getting Custom post category from Form

Its pretty much what you already have, just add the following after $pid = wp_insert_post($new_post);: #categories if( !empty ( $_POST [‘categories’] ) ){ update_post_meta ( $pid, “_testimonials_category”, stripslashes ( $_POST [‘categories’] ) ); } I would probably advise you to change the name of this from categories though to something more relative, like testimonials_categories Then … Read more