Articles of post type

How to copy a custom field from the user's CPT to the user's normal posts

Each author has a single post in a CPT. In their CPT post they have a custom field. Each author can also post to a normal post type as much as they like. How can I copy the custom field of the user’s CPT post copied to all their normal post type posts they subsequently […]

Custom post type in theme not appearing

I have a theme on WordPress 4.4 which has this file included in functions.php: <?php function post_types(){ $labels = array( ‘name’ => __( ‘Newsletters’), ‘singular_name’ => __( ‘Newsletter’), ‘menu_name’ => __( ‘Newsletters’), ‘name_admin_bar’ => __( ‘Newsletter’), ‘add_new’ => __( ‘Add New’), ‘add_new_item’ => __( ‘Add New Newsletter’), ‘new_item’ => __( ‘New Newsletter’), ‘edit_item’ => __( […]

Registered Post Type Isn't Showing in Admin Menu

I have a custom function to make posts hierarchical by registering a post type in my functions.php like this: register_post_type( ‘post’, array( ‘hierarchical’ => true ) ); After uploading, the posts item from admin menu just disappears. Why is this happening?

How do I add a category to my post_type

I have a section in my dashboard called “services”. I have 4 services I have 2 categories for these services: residential and commercial 2 of the 4 services have the category “residential”, and the other 2 “commercial” As it is now my services page is pulling up all 4 services. Question: What code do I […]

pop-up lighbox with AJAX

I need to create ajax script where user choose a post type and after choose post type post show on a light-box or any thing but without loading. I can’t get an idea. Please give me a idea to improve this script. <select> <?php $args = new WP_Query(array( ‘post_type’ => ‘post’ )); while($args->have_posts() ) : […]

how to get random post id by using post type

I need to get a post ID’s random manner… Something I tried like this, $args = array( ‘post_type’ => ‘adzones’); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $id = the_ID(); echo do_shortcode(“[pro_ad_display_adzone id=”.$id.”]”); endwhile; Here I’m try to display an add post inside the loop but it won’t work for […]

Querying for multiple post types in SQL

My site is using a plugin for displaying an archive widget. It only displays the ‘post’ post-type. I currently have three different post-types. Looking through the code I found: $where = apply_filters( ‘getarchives_where’, “WHERE post_type = ‘post’ AND post_status = ‘publish’ AND post_date <= now()” ); It seemed like a easy fix. First I changed […]

Dynamic pages for linked categories and content

Not new to Stack Exchange (i.e., Stack Overflow), but new to WordPress. I want to understand the power of categories, posts, custom post types, and the ability to generate dynamic content using them. This question may seem narrow, but use your imagination: this general idea is something many WordPress sites would want to execute. Question: […]

Conditional based on post meta

I’ve got this bit of code in my functions.php : // Disable theme single views function fq_disable_single_cpt_views() { $queried_post_type = get_query_var(‘post_type’); $cpts_without_single_views = array( ‘ait-item’ ); if ( is_single() && in_array( $queried_post_type, $cpts_without_single_views ) ) { wp_redirect( home_url( ‘/sorry’ ), 301 ); exit; } } add_action( ‘template_redirect’, ‘fq_disable_single_cpt_views’ );’ Which is redirecting single-page requests of […]

How to hide specific post type from archive?

Assume there is a post type called profilepost that I wanna hide from all kinds of archive. (but not changing the post status to private) I tried to get all post ID that belongs to this post type. The code below failed. global $wpdb; $profilepost_ids = $wpdb->get_col( “SELECT ID FROM wp_posts where post_type = ‘profilepost'” […]