The code is fine, I can’t see any need to modify the query – I think you’re missing the third argument in your get_post_meta call
:
$postACF_sc = get_post_meta($postId, 'sc_link', true /* $single */);
You might also want to add this snippet just before the foreach
to save multiple database queries:
update_postmeta_cache( wp_list_pluck( $posts, 'posts_id' ) );
Related Posts:
- Getting wrong relationship value in $args in wp_Query?
- How to get data from WordPress $wpdb into React Gutenberg Blocks Frontend?
- Auto-complete or auto-suggest from stored data in database
- pull data from wordpress database
- Should I use wpdb prepare?
- Fatal error: Class ‘ms\WP_Query’ not found on plugin initialization [closed]
- How to add multiple custom URL variables?
- Why Does get_posts() Return an Empty Set?
- How is the data stored in the database?
- get_posts / WP_Query Memory size of 134217728 bytes exhausted
- add_filter and remove_filter added before and after wp_query
- How to get all images and their thumbnails from wp media library
- How to create a dynamic page based on form data with a plugin?
- How to Display Custom Post Type’s Gallery (images ) in Through WP_Query
- Handling form request from plugin file
- How can I free up the memory used by update_post_meta?
- Passing array of strings to a SQL statement in a WordPress plugin
- Activation hook not creating table
- Is the usage of ON DELETE CASCADE wrong or not allowed on wordpress?
- How to edit mySQL wp_posts table from plugin php?
- Version upgrade: can my plugin filter the SQL statements issued during a database upgrade?
- Cannot search post by taxonomy
- How to get orders with used coupon in WooCommerce
- WP_Query with tax_query, order by most ‘matches’
- query users by role
- How to print raw query from WP_Query class just like in CodeIgniter
- WP_Query returns no results
- Finding posts containing matching array elements in a meta field usign WP_Query
- Create a custom display order in the main menu
- manage_posts_custom_column, showing serial number using increment in loop
- Error : “Cannot use object of type WP_Post as array in”
- Proper way to run wp_query from inside a plugin
- using new WP_Query in save_post function alters $post
- Slow WP_query due to nested wp_query. Need Suggestions
- WordPress database error for query INSERT INTO
- How to connect to AWS RDS external database (not for the core WordPress db)
- How to create database table, add data, update and delete using wpdb via plugins?
- WP_Query filters
- How to fetch only current hour posts?
- How to get Metabox custom field to show checked if value is updated using post meta query?
- WordPress pre_get_posts with combined results of two queries (OR)
- How to add user details to different tables immediately after user registration
- Search: how to extend the existing search to include a custom table
- mysql_real_escape_string() vs. esc_sql() in WordPress
- how to get all the child category name in a specified category name?
- How I can use order by of the custom post title?
- How to query children by post name/slug
- $wpdb->prepare with LIKE and sprintf
- Prevent WordPress automatically processing certain URL queries
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- Store custom meta box data as serialized array
- how to load the comment template from a plugin
- Two different wordpress sites – same server and IP address. Gaining Access to database 1 of 2
- How remove trashed WooCommerce orders from wc_get_orders() result?
- How can I programmatically change a MySql variable (foreign_keys_check)?
- WordPress WP_Query without query GET parameters
- What might be the reason of Couldn’t fetch mysqli_result on another domain?
- $wpdb->prepare is not working like mysql_real_escape_string
- Get post thumbnail in WP_Query
- Brainstorm – Slow Query from Plugin Need to Speed It Up
- Create an user on external database
- Get Posts by IDs (optionally)
- What could cause a WP Option to get truncated?
- Adjust query on single
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- Foreign wp_users ID in custom plugin DB table?
- How to Get Last ID?
- WP_Query order posts by category
- Multiple dynamic Tax Query – pass taxonomy argument from array
- WP_Query not ordering correctly
- How to check category name available or not
- Home page is not loading, where in other pages are displaying on the site
- how to create a shortcode from a variable in plugin
- WordPress how do I echo SUM from a column of a MySQL table by user id AND type_operation
- Why is that only the first row getting inserted into Mysql table when i import csv file on backend custom plugin?
- Error Connecting to Database WHEN Installing WordPress on XAMPP [Tried All the Usual Stuff] (Pics Included)
- Group By in a Metaquery
- WP Query date_query with several date range
- WordPress delete mysql rows with string
- Organising and completing posts (mark as read and hide)
- Making Woocommerce optimized for more than 500k products
- Post Pagination does not working on WP-Query
- WP Query Relations / Compare
- Plugin MySQL SELECT custom data and filter on user meta
- How can I query 3 posts from diferente categories (one of each category)
- sql query not working in wp plugin
- $wpdb Mysql trigger problem
- Query only title/field/featured media of posts [closed]
- $wpdb how can i save my postmeta table before querying it
- Can’t get query string in ajax call
- Get custom wp_query search results to appear on search.php
- loop and in admin header problem
- Nothing happens on WordPress Update command
- How do I query posts and have their related taxonomies returned in the results?
- Best Way to Inventory the Media Library of a 200+ Multisite Installation?
- $_GET vs get_query_var()
- What is the meta_query key name for the woo product average rating? [closed]
- get the queried_object of an url
- Return custom product in ajax call loop
- filter on get_posts efficiently