I have been trying to achieve this for the past two days but nothing works. I am attempting to build functionality to search any post, page, and a couple other custom post-types by a tag. I have created a plugin which registers a taxonomy called search_tag. search-tags.php require_once __DIR__ . '/includes/search-tags.class.php'; function search_tags_closure() { $search_tags = new Search_Tags; $search_tags->create_taxonomy(); } add_action('init', 'search_tags_closure'); search-tags.class.php class Search_Tags { const NAME = 'search_tag'; const LABEL = 'Search Tags'; protected function get_post_types() { $args …
I have a WordPress multisite with one main site and four sub-sites. In a PHP template on my main site, I would like to get the posts from one of the sub-sites and print the permalinks to the page. How is this done? My code is below--when this code is executed, permalinks are indeed printed to the screen, but they are incorrect--the post name is correct, but the path is incorrect. $tp_blog_id = 4; switch_to_blog( $tp_blog_id ); $posts = get_posts( …
I'm using this code to populate the dropdown menu in a meta box. $parents = get_posts( array( 'post_type' => 'jhk_story', 'orderby' => 'ID', 'order' => 'ASC', 'numberposts' => -1, 'exclude' => array(121, 131, 138), ) ); This post_type contains the parents of a post_type 'jhk_frames', which are the only child. So, the children contain in their post_parent field the post_ID of their parent. The parent contains in their post_parent field still the default zero. My question is: how do I …
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 …
Currently in one of my php files, I retrieve all of the public posts like this: $posts = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'post' )); However, this only returns public posts, and I would like to store all posts, both public and private, in the $posts variable. How can I accomplish this?
I'm trying to rewrite my search.php to search only for the post titles because I have a ton of posts published to my site (around 400k), which slows down the search speed to about 20s per search. <?php get_header(); $search_term = $_GET['s']; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $posts = new WP_Query( array( 's' => "$search_term", 'ep_integrate' => true, 'post_type' => 'post', 'posts_per_page' => 21, 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged, ) ); ?> <?php if …
I had a website built on Woocommerce for me, but no longer have access to the Developer. I'm not a programmer so anything beyond CSS changes gives me quite a bit of problems. There is a piece of code that was working fine, but I have added an additional item to the site and now it only will fetch the most recent item added. I believe the problem is that get_posts is only collecting the latest product and I need …
I want get 3 posts from event custom post type. But i want to do that by category priority. If "featured" category has 3 upcoming event then i want to show 3 posts from it, if "featured" category doesn't have 3 upcoming events then i want to get posts from other category+posts without any category too. The end result will return 3 upcoming event. I'm a little confuse about how can i add that condition parameter on WP_Query. Current code(that …
I have the following code. It allows me to show sub categories and documents within them. The thing is, a sub category may contain further sub categories. The code below will show documents belonging to a sub-sub (grand child) category at sub (parent) level. Please can anyone shed light on how to solve this so document only show underneath the category they are directly under? In addition, highlighting what is a sub-sub (grandchild) category as well? All posts titles should …
This works, but I will need it to make 8 different lists on the page, using same meta key but 8 different meta values. Is there a more efficient way to achieve this rather than repeating the same code 8 times? <?php $posts = get_posts(array( 'numberposts' => -1, 'post_type' => 'page', 'meta_key' => 'my_meta_key', 'meta_value' => 'meta_value_1' )); if( $posts ): ?> <h4>Pages with Meta Value 1:</h4> <ul> <?php foreach( $posts as $post ): setup_postdata( $post ); ?> <li> <a …
I am building a meta query array and all fields for the user are optional so some might not have any data. But there is also an option which requires a date query. I am still checking to see if this is working but not sure as of yet. Is this correct and if not, what would be the right way to do it? Not sure if there needs to be an OR condition in here somewhere. $meta_query = []; …
I am trying to use get_posts to return data between certain dates but I always get an empty result even though there is a lot of data. This is for a custom post type. $args = array( 'post_type' => 'bookings', 'fields' => 'ids', 'post_status' => 'any', 'posts_per_page' => -1, 'date_query' => array( array( 'after' => '2022-01-01', 'before' => '2022-06-01', 'inclusive' => true, ), ) ); $data = get_posts($args); die(var_dump($data)); I also tried something like the below to get a specific …
So, I have a custom content type called "team" where I have an ACF field attached called "external" which is a checkbox. I am currently getting all the posts by passing the following arguments array to the get_post function. $args = array( 'posts_per_page' => -1, 'offset' => 0, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'team', 'post_status' => 'publish', ); What I'd like to do is run this in two functions checking if the field is or is not …
I have a ACF select field which takes multiple value. Now I want to use get_posts() to get those custom posts. My arguments look like this: $party = 'test1'; $function = 'test1, test2'; $args = array( 'numberposts' => -1, 'post_type' => 'event', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'party', 'compare' => '=', 'value' => $party, ), array( 'key' => 'function', 'compare' => 'IN', 'value' => array($function), ) ) ); $items = get_posts($args); But this does not work! …
I have a Custom Post Type of 'ITEM' that allows the admin to add an 'Item Number' using an ACF text field. In another Custom Post Type of 'GROUP' the admin can use an ACF Repeater to enter multiple 'Item Numbers' for 'ITEMS' to associate with this GROUP. I need the loop to show all posts that have an 'Item Number' that matches a number entered into the Repeater on the Group Page. I'm using get_posts() to query on a …
I rewrote the code galleries and stopped at the pagination. How can I get the maximum number of pages? at the moment I can not define it, and put a test for the number 5. (Here "for ($ i = 1; $ i <= 5; $ i ++)" here "if ($ paged <5))." And how to make that work offset parameter in pagination? Now when I put the parameter offset, pagination will not work correctly. I need to post 16 …
I'm writing shortcode which must show all orders placed by current user. I followed this two guidee to get them: https://www.businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-product-object/ https://www.businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/#colophon However shortcode not working. Get the following error on line 31 of my file - Fatal error: Uncaught Error: Call to undefined method WP_Post::get_items(). On line 31 i have this: foreach ( $order->get_items() as $item_id => $item ) I'm relatively new to this, I don't understand what I'm doing wrong, can anyone help me correct this mistake? I …
I made a new page in admin panel like this. I want my Query here to be main_query so the other plugins could hook it, modify limits, etc... add_action('admin_menu', function (){ add_submenu_page('edit.php?post_type=ticket', __('Board', 'askanban'), __('Board', 'askanban'), 'edit_posts', 'askanban', array( $this, 'askanban_display_board' ), 1); }); public function askanban_display_board(){ $args = array( 'post_type' => 'ticket', 'posts_per_page' => - 1, ); $query = new \WP_Query( $args ); $query->is_main_query(); // FALSE HERE!!!!!!! $posts = $query->posts; print_r($posts); } I read tons of info like this …
How can I get a random category name one at a time?? The post may have multiple category instead of a single category. I just want to show a single category name in the post grid loop. $home_blog_posts = get_posts(array( 'posts_per_page' => 3 )); Thanks.
I have an issue with my orderby using get_posts(). I want to order in alphabetical order a list by city name using a custom meta field, but it comes back empty. However when I orderby title, the list is displayed with no issues. I activated WP_DEBUG and no errors or notices were found. I checked the query in hopes that I was using the wrong meta_key, but everything looks as it should be. Am I missing anything? SELECT wp_posts.* FROM …