You don’t need to modify the global current post, just use the get_posts() function instead of WP_Query().
function get_root_project_value( $meta_key ) {
if ( empty( $meta_key ) ){
return false;
}
$args = array(
'post_type' => 'slug',
'meta_query' => array(
array(
'key' => 'project_is_root_project',
'value' => '1',
),
),
'posts_per_page' => 1, // If you want only one result, set to 1 instead of -1
'fields' => 'ids', // To get only ids. No need more
);
$project_ids = get_posts( $args );
if ( !empty($project_ids) ){
foreach ( $project_ids as $project_id ) {
return get_field( $meta_key, $project_id );
}
}
return false;
}
Related Posts:
- When tax_query used, results disappear (0 =1 produced)
- WP_Query in functions.php
- Gravity Forms field entries into wp_query loop [closed]
- list tags with count in author profile page
- wp_is_mobile dequeue not working
- Having a Function Inside of the Loop
- Wp_query function to search from product_title ‘OR’ product tags name
- Display tags that only appear in one category
- Custom Query Not Paginating
- Wp-query Order By problem
- How is $current_page passed in woocommerce_account_orders function?
- How to apply the ‘current_page_item’ class to an archive page in `wp_list_pages()`?
- Filter for replacing the WP_query object for a given category
- Create a CUstom Archive by Year, but just for a Single Category
- Updating custom query var with multiple values
- WP_Query for Attachments not working as expected
- query_vars treat as single var from URL
- Optimizing multiple WP_querys into one call?
- Query is not work
- How to Delete Posts by title?
- Integrating custom API for post content into Admin interface & Public Website [closed]
- Insert image between X number of posts but on specific paginated pages?
- How do I get the current edit page ID in the admin?
- Does hooking into the same action multiple times drain memory?
- ajax category filter
- Apply custom role capabilities to administrator (without plugin)
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Different wp_mail_from and wp_mail_from_name for specific situations
- Linking thumbnail to full size image
- is_front_page not working in functions.php
- VERY new to coding – keep breaking site trying to add to functions.php
- Restrict user registration to emails on a single domain
- How to enqueue JavaScript for specific WordPress pages only?
- Passing HTML in WordPress Shortcode arguments
- Can I use require() function in a template file?
- Exclude Empty Child Categories in Menu
- Convert User ID’s to User Names in a single.php file
- Custom roles can’t access to wp-admin
- How to specify which Gutenberg blocks are available in the editor for a page template
- Custom Shortcode, functions PHP WP_Query loop
- How to filter out shortcode when displaying the_excerpt() in the loop?
- wpautop – disable tags, keep tags
- Logout hyperlink within a sub-menu
- How do I pass arguments for multiple functions hooked to a single action?
- Manipulate Permalink
- Theme functions.php file auto delete everyday [closed]
- How to get the index number of the posts?
- Two Types of settings in WP – The Doubt
- Custom Attachment Caption Fields
- Generating dynamic css into custom file [closed]
- How to call particular funcion when the check box is checked in plugin options page
- Events: Check for other event with same start date and category [closed]
- Function coding error concatenating quotes I think
- Need print logo without any ID & class
- Can we create our own theme’s function.php?
- Not all CSS elements transferring via parent to child?
- Unable to return values from function
- Show some menu sub items as dropdown under a menu item
- Set “woocommerce_is_purchasable” to false for specific “$product->is_stock_status”
- The correct way to add a JavaScript in the functions.php [closed]
- How to remove some item from WordPress Dashboard for user Author
- Disabling Author Page only for subscribers
- Showing user profile data on front-end
- How to register a menu based on a ACF condition
- How to convert raw url to hyperlink?
- Split single-review.php to two parts
- Trying to get property of non-object in: $wp_query
- Breaking up multiple words and inserting an image after first word
- get content from page through AJAX
- colorbox not loading in
- The work of WordPress Function update_post
- how can I change all wordpress media file url to custom cdn url?
- Changing the HTML of notices in WooCommerce [closed]
- Save_post – Warning: Cannot modify header information
- How to use WP conditional tag in a functions.php with OCEANWP Theme?
- Modify content inside post before first publish
- Pass an argument into a function to extract from array
- function class doesnt work
- how to remove a tag in the_category function
- Load CSS file conditionally
- my wordpress doesn’t save items to customized widget area
- Copying a widget class to functions.php results on a blank page
- save_post doesn’t correctly process function call with php class
- No compression occurs on my jpegs after adding jpeg_quality hook to my functions.php file
- Changing the register url is not working
- Newest comments first not working
- Pass arguments to function class with do_action()
- How to a override parent theme page that has been included with require_once?
- Display most popular posts
- Can I use a function to return HTML and the result of another function?
- Excerpt length: get 2 paragraphs
- Remove heading tags on line break
- Add custom fields after post/page title
- Sort results by name & asc order on homepage
- Add the title of a widget as an ID – for anchor links
- I want to add the alt attribute to all the photos!
- Creating mixture of shortcodes to use in the visual/text editor
- Correct php syntax to add an image in wp functions.php
- function to show youtube videos within excerpt – if condition and apply_filters
- How to automatically load Google Fonts on pages only as they’re used?