How to make all post under post_type to draft or return a 404?

Not tested, but if I have inderstood the question correctly, please try the below solution. Articles post type will return a 404 but posts under movies categories will not. Code goes in a functions.php of your child theme. function rr_404_custom_post_types() { global $wp_query; if (is_single() && !($wp_query->post->post_type == ‘movies’)) { $wp_query->set_404(); status_header(404); } } add_action(‘template_redirect’, … Read more

Target Post Type from array Query

$my_query->post_type refers to the post type of the query (in this case an array), and not the results. (Its recommended to use $my_query->get(‘post_type’) too, but anyway…). To get the current post’s (in the loop) post type: $post_type = get_post_type(); You can also use that function outside the loop by passing the post object / ID. … Read more

Show post type taxonomy

Set the public parameter in register_post_type to true like this: public’ => true, public (boolean) (optional) Controls how the type is visible to authors (show_in_nav_menus, show_ui) and readers (exclude_from_search, publicly_queryable). Default: false ‘true’ – Implies exclude_from_search: false, publicly_queryable, show_in_nav_menus, and show_ui. The built-in types attachment, page, and post are similar to this. And create a … Read more

Displaying only the current category in template page

Use the following code: <?php if (have_posts()): while (have_posts()): the_post(); ?> <h5><a href=”https://wordpress.stackexchange.com/questions/85120/<?php the_permalink(); ?>”><?php the_title(); ?></a></h5> <?php if ($content != ‘no’) { the_excerpt(); } endwhile; endif; ?>

Querying for multiple post types in SQL

Couple of things to note; one’s a WordPress issue, the other an SQL issue: For WordPress, instead of editing the plugin files directly, you should use the ‘getarchives_where’ filter it provides, and change the query there. For SQL, in order to query for multiple post types, you need a conditional statement in the query, so … Read more

Conditional based on post meta

to add a condition on a meta value, you can modify the test like that : function fq_disable_single_cpt_views() { $queried_post_type = get_query_var(‘post_type’); $cpts_without_single_views = array( ‘ait-item’ ); $_ait_item_item_featured = get_post_meta(get_the_ID(), “_ait-item_item-featured”, TRUE); if ( is_single() && in_array( $queried_post_type, $cpts_without_single_views ) && (“0” === $_ait_item_item_featured) ) { wp_redirect( home_url( ‘/sorry’ ), 301 ); exit; } }

How to edit default post settings

Refer to the manage_posts_columns filter, and also the manage_posts_custom_column action. Here is a really old tutorial, linked from the Codex, that might be instructive. (Caveat: it’s from 2007; some things might be out of date.) Edit The above hooks are for the manage posts screen. To remove/add meta boxes to the edit post screen, see … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)