Get_posts not returning any posts when used with switch_to_blog

I'm attempting to pull in some order information from the "shop_order" post_type. This is on a multisite network, so I'm using switch_to_blog(1). When I set the post type as "post" it works great and I get the posts from the correct site. When I set the post_type to "shop_order" I get nothing, despite there being 20,000 'shop_order' records in the database. switch_to_blog(1); $args = array ( //'post_type' => 'post', 'post_type' => 'shop_order', 'posts_per_page' => 2, ); $posts = get_posts( $args …
Category: Web

How to set "manage categories" capabilities on a post type taxonomy but not on the general categories?

I want to set "manage_categories" capabilities on a post_type taxonomy but not on the general categories? I've added to register_taxonomy: 'manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'read' 'edit_post' => 'edit_video', 'read_post' => 'read_video', 'delete_post' => 'delete_video', 'delete_others_videos' => 'delete_others_videos', 'edit_posts' => 'edit_videos', 'edit_others_posts' => 'edit_others_videos', 'publish_posts' => 'publish_videos', 'read_private_posts' => 'read_private_videos', How do I prevent this user from managing the general site's categories and edit only these post type taxonomies categories? What should I add? …
Category: Web

Filter Media by attached page or blog post in Library

I am trying to create a filter using restrict_manage_posts that will filter all media according the page or post type that have been attached to. Actually i need to create a filter that refers to the Uploaded to column. I have been trying many variations with no luck. function media_add_uploaded_to_dropdown() { $scr = get_current_screen(); if ( $scr->base !== 'upload' ) return; $attached_page = filter_input(INPUT_GET, 'attached_page', FILTER_SANITIZE_STRING ); $selected = (int)$attached_page > 0 ? $attached_page : '-1'; $args = array( 'show_option_none' …
Category: Web

Why does 'exclude_from_search' exclude a custom post type from WP_Query?

In WP 3.1, it appears that setting 'exclude_from_search' = TRUE for a custom post type excludes the post type not just from searches on the front-end, but also from any post query using 'post_type' = 'all'. I can imagine plenty of scenarios where a plug-in developer would want to access ALL post types, even those excluded from front-end searches. Is this a bug, or is it just poorly documented? Backstory: I have a custom post type using a custom "Post …
Category: Web

Custom post type pagination 404 fix?

Been trying to get this working all day but haven't had any luck... I have a custom post type called 'news' and an archive template (archive-news.php), here I'd like to show 2 posts with pagination, which works fine, until I try to go to the 'next page' (/news/page/2) which returns an error 404. Any idea how to fix this / what I'm doing wrong? I've literally spent all day trying to find a solution to this by searching Google and …
Category: Web

How do i know the current post type when on post.php in admin?

Im trying to do something with an admin_init hook if - and only if - the user is editing a post (post.php) with post type "event". My problem is that, even though wordpress points to a global variable calls $post_type. if i do: global $post_type; var_dump($post_type); It returns NULL. but if I do this: global $pagenow; var_dump($pagenow); it returns my current page. i.e. "post.php". I looked into this function $screen = get_current_screen(); but thats not declared until after the admin_init …
Category: Web

Why is my custom post content only viewable when signed into Wordpress?

I've created a custom Post type called 'Data' to display content on a Wordpress site. The content works and is displayed if viewed when signed into Wordpress. Howevever, if you view the same URL when not signed into Wordpress (Incognito), the page appears blank. Is there a soultion to this? Snippet from functions.php: // Our custom post type function function create_posttype() { register_post_type( 'Data', // CPT Options array( 'labels' => array( 'name' => __( 'Data' ), 'singluar_name' => 'Data', ), …
Category: Web

Target only single product page

At first sorry for my bad English! I try to hide #mceu_27-body and #wp-content-editor-tools on products page (editing mode) like on the pics for certains authors! This work find : add_action('admin_head', 'wwc_my_custom_css'); if (!current_user_can('edit_pages') ) { function wwc_my_custom_css() { echo '<style> #mceu_27-body, #wp-content-editor-tools{ display:none !important; } </style>';} } But it affect all posts type and I just want it on products post type so I tried that but it doesn't work : add_action('admin_head', 'wwc_my_custom_css'); if (!current_user_can('edit_pages') && is_product() ) function …
Category: Web

paginate_links appearing on page but it doesn't actually paginate - pagination on a static page with a dynamic `post_type` argument on a static page

I'm doing a custom post loop like this; <?php $args = array( 'post_type' => $resourcesPostTypes, 'post_status' => array('publish'), 'orderby' => 'date', 'order' => 'DESC', 'post__not_in' => array(15552, 15554, 15555), 'posts_per_page' => $posts_to_display ); $query = new WP_Query($args); $resourceCount = 0; if ($query->have_posts()) { while ($query->have_posts()) { // .... rest of everything here And I needed to add pagination. After some extensive research I found this: <?php echo paginate_links( array( 'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ), …
Category: Web

Is it possible to set public to false for the native WordPress blog

I am using my WordPress posts to generate excerpts to go to an outside URL instead of the permalink. I know how to set a custom post type's: public => false but I don't know how to do this for the native WordPress blog. I don't want a permalink page generated because I don't want duplicate content. Is there something I can add to the functions file for this? Also, I'm not sure if I should be using publicly publicly_queryable …
Category: Web

get_the_post_thumbnail_url('full') returns empty from custom post type

I'm trying to display the full size image of the single post from a custom post type that I created, below is what I've tried <?php $args = array( 'post_type' => 'press', 'order' => 'ASC', 'post_status' => 'publish', 'suppress_filters' => false ); $press = new WP_Query( $args ); if ( $press->have_posts() ) { ?> <?php while ( $press->have_posts() ) : $press->the_post(); ?> <div class="col-sm-4 mb24"> <article class="post-article bg-white"> <div class="article-img"> <?php if( has_post_thumbnail() ){ ?> <div class="img-box position-relative overflow-hidden"> <a …
Category: Web

Error in Fetching Custom Post Type parent Category URL (slug)

I have this code for breadcrumbs that works fine except the custom post type parent category URL and the category TITLE. The parent category URL is does not return the valid (correct) slug while its title (anchor) returns a text with description on it like CATEGORY - BOOKS. Although I am a bit of a mediocre in coding but I am open for learning. I figured out the code responsible for displaying the invalid parent category is below elseif ( …
Category: Web

How do I make the comment disappear after deleting from the database?

I can delete the comment from the database with this code, however when the page is loaded again the comment will still be there. I need to update again to disappear. How do I resolve this? <?php if( 'POST' == $_SERVER['REQUEST_METHOD'] ) { set_query_var( 'commentid1', $_POST['commentid'] ); wp_delete_comment( get_query_var( 'commentid1'), true ); }; ?> <form class="delete-comment" action="" method="post"> <input type="hidden" name="commentid" value="<?php comment_ID() ?>" /> <p align="right"> <input type="submit" value="Delete" title="Delete" /> </p> </form>
Category: Web

Custom Post Type Single Page is not working

I wanted to know, why my single custom post type isn't working. Everytime I wanted to open the single post type it automatically gets back to the homepage. Please help! Here is my code: // Team im Backend hinzufügen function register_team() { $labels = array( 'name' => __( 'Team', 'team' ), 'singular_name' => __( 'Team', 'team' ), 'add_new' => __( 'Neues Mitglied', 'team' ), 'add_new_item' => __( 'Neues Mitglied', 'team' ), 'edit_item' => __( 'Mitglied bearbeiten', 'team' ), 'new_item' => …
Category: Web

Wordpress private post won't display to other admins

By default Wordpress private posts are visible to all admins right. But on this build for some reason private posts are only displaying (on the page) to the admin that created it. I'm perplexed. I need all admins to see the private posts displayed. This is a custom post type using a custom query so maybe there's something I did there. // query upcoming webinars - Sort by date from date Picker $args_upcoming = array( 'cat' => $thiscat_id, 'numberposts' => …
Category: Web

Unique IDs for Post Types and Taxonomies

Sometimes I have duplicate IDs between Post Types and Taxonomies, I know this happens because they are stored in different tables but I wish it was possible to have a unique ID for each thing in WP, is there a way to achieve this?
Category: Web

Only show meta on one post type on search results page

I want to remove the post meta from all post types that are not "posts" from my site or at least from the search results. Im currently using the Jnews theme and in the search results page I get all post types (posts, pages, products) but I'm only interested in leaving the post meta (.jeg_post_meta) for posts and removing it for all other post types like pages, products and others that the results page can bring. .jeg_post_meta is the style …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.