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 want to display images under for each comment but images store in database as serialized a:3:{i:0;i:775;i:1;i:776;i:2;i:777;} I wrote this code print_r (get_comment_meta( $comment->comment_ID , 'reviews-images', true )); but it outputs this * Array ( [0] => 778 [1] => 779 [2] => 780 [3] => 781 [4] => 782 ) 10 then I tried this echo get_comment_meta( $comment->comment_ID, 'reviews-images', true ); not worked . Please help how can I get image urls instead of this output
I'm trying to change text on the table depending on the meta value I give (number). if meta value >= 7, number text on table changes to green. else if meta value >= 4, number text on table changes to yellow. else, number text on table changes to red. However, this code doesn't work. <script type="text/javascript"> function change_color_text (num1) { var rate_num = num1; if(rate_num >= 7) { rate_num.style.color = "green"; // green } else if (rate_num >= 4) { …
Sorry guys, had to post this again as site wouldn't let me respond to comments (new account). I have been working on some code to decrease quantity of a variable product based on the numeric values of a custom field. This is working fine, however I have implemented a checkbox that will essentially TURN ON/OFF the feature on each product. This custom checkbox also works fine, appears in 'Product General Settings' and is storing the data fine - I have …
At cascadeoc.org/results I have results sorted by a Custom Field, "event_date_results" which is the date the event happened (not the date the post was published). However, when there are multiple results from the same day, I'd like to further control post order by published date and TIME. How can I add this second orderby filter? Here's what I have: <?php $query = new WP_Query( array( 'post_type' => 'result', 'posts_per_page' => 100, //'paged' => $paged, 'meta_key' => 'event_date_results', 'orderby' => 'meta_value_num', …
We have a custom post type, events. This has a custom field called event_start. In trying to query only past events, I'd like to limit the query with this basic logic: post type is events event_start is not empty event_start is a date before today For this I've composed what seems to be a straightforward query: $args = array( 'post_type' => 'events', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'event_start', 'value' => $today, 'compare' => …
is it possibile to search custom post type product by _sku or other custom meta field with input text field? I don't want to use plugin, just need custom WP function. I have found this solution for search only by title: function __search_by_title_only( $search, &$wp_query ) { global $wpdb; if ( empty( $search ) ) return $search; // skip processing - no search term in query $q = $wp_query->query_vars; $n = ! empty( $q['exact'] ) ? '' : '%'; $search …
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 …
I have a search form with two dropdowns showing custom terms and two text fields for custom meta keys, The search work with tax_query but meta_query has no result. Here is the pre_get_posts hooks callback function. Why didn't get results through meta keys filters? function sm_pre_get_posts( $query ) { // check if the user is requesting an admin page // or current query is not the main query if ( is_admin() || ! $query->is_main_query() ){ return; } // edit the …
I have custom-post-type company and taxonomy services for this CPT. I have created meta-field service_[id]_price for companies and fill this field with a number. If this company has not price for this service, I fill 0 in this field. On the services page, I need a list of companies sorted by current service price ASC. In this case, I first get all companies with "0" value in this field. But I need to get all companies where this field has …
I have page template that stores reservation input fields, I would like add link to that specific page using meta box but my meta box doesnt work in extras.php and meta-tags.php, I would like to know where do I do a mistake or what should I do to retrieve meta value anywhere in all pages? my function is: function test_button() { global $post; $bsub; $button_link; $button_link = get_post_meta(get_the_ID(), '_but_subtitle', true); echo '<a href="'.esc_url( get_page_link( $button_link ) ).'">'.esc_html__( 'Reservation', 'text-domain' ).'</a>'; …
I'm really struggling getting this seemingly simple thing to work. I have a list of "vendors" as a CPT. They have metadata like "contact name" and "last invoice date". I'd like to have the "archive" page for these vendors show a simple table: Name Contact name Last Invoice Joe's Plumbing Joe Anderson March 31, 2021 I can not seem to figure out how to get metadata into this. I'm also struggling with getting Wordpress to stop inserting <h2>s, but at …
I would like to indicate that if you do not have the first_name filled in when logging in, you will be redirected to a specific page, for example /onboarding and if the first_name field is filled, you would be redirected to the home page. I would like it to always perform the check and redirect whenever first_name is empty I am trying the following code but it does not work. function login_redirect( $redirect, $user ) { // Get user meta …
I am trying to fetch custom post related to a User. I am using below code. $args = array( 'post_type' => 'tasks', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'users', 'id' => $user->ID, 'compare' => '=', ), ), ); $query = new WP_Query($args); $posts = $query->posts; But I am not getting any output.
I'm triing to print some values stored in a post meta. My post meta_values looks like this : a:3:{s:6:"amount";s:117:"€2.00";s:6:"entity";s:5:"11854";s:9:"reference";s:9:"800146779";} I'm using the function bellow in order to try to print the Amount, the Entity and the Reference but all I'm getting is the first character of the Value. Here's my function: function get_value( $order, $parameters ) { $order_id = Compat\Order::get_id( $order ); global $wpdb; $ref_multibanco = get_post_meta($order_id,'_stripe_multibanco', true); // select array return $ref_multibanco['amount']['entity']['reference']; } And since i'm asking I would …
I have a meta_key called "_ordre" and each time I create a new custom post, a new meta_value is set for that meta_key. The thing is, when I set the value of '_ordre' to 0, the meta_value is not saved into the database. Anything else is ok but 0. here is my code: function wp_audio_save_meta( $post_id, $post ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( !isset( $_POST['wp_audio_posts_nonce'] ) ) return; if ( !wp_verify_nonce( $_POST['wp_audio_posts_nonce'], plugin_basename( …
I am beginner at customizing wordpress but have some experience in PHP coding. I'm struggling to figure out how to display all existing meta keys (custom fields defined by ACF) for all users that have role "author". Default fields display ok, but cannot get values of those meta keys / custom fields. The code below was created with wp generator and manually expanded. I tried here with only 2 default fields (user email and display name) and 2 meta custom …
Looking for a method to nest AND/OR relation in meta_query based on array serialized values. Reviewed these already: Query multiple meta key values? WP Meta Query for some meta (array) values I understand that the serialized data 'should not' be used to search/filter (or first needs to be pulled out to do so outside the SQL) BUT I would like to put it out there so see if nesting could do the trick. E.g. Data [ meta_value field1 = 'abc' …
Based on multiple searches, this is the code I'm trying to sort by two different meta key values. 'meta_query' => array( 'relation' => 'AND', 'listing_order' => array( 'key' => 'atsc_bod_listing_order', 'compare' => 'EXISTS', ), 'last_name' => array( 'key' => 'atsc_bod_last_name', 'compare' => 'EXISTS', ), ), 'orderby' => array( 'listing_order' => 'ASC', 'last_name' => 'ASC', ), I want to first sort by a numerical value and then if the numerical values are the same, sort by last name. This code returns …