80790

How to pass multiple ids to post_parent?

Question:

So i need to pass multiple values but i dont know how? Any suggestion?

$myarray = array('144', '246'); $images = get_children(array( 'title_li' => '', 'post_parent' => $myarray, 'sort_order' => 'DESC', 'sort_column' => 'menu_order' ) );

Answer1:

You can do this with <a href="https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters" rel="nofollow">WP_Query</a> object :

$children_query = new WP_Query(array( 'post_type' => 'attachment', 'orderby' => 'menu_order', 'order' => 'DESC', 'post_parent__in' => array('144', '246') )); if($children_query->have_posts()){ while($children_query->have_posts()){ $children_query->the_post(); // your display } wp_reset_postdata(); }

This will look for all media attached to any post of the array

Recommend

  • Webmethod is not fired by jsTree
  • Submit drop down on click
  • Get Featured Image of Pages - WordPress
  • How to display sub child pages only when on direct parent page?
  • Return multiple values in an array from an array of objects
  • DRF serializer change field to read_only for some model instances
  • Display number of posts from a certain category?
  • left join only fetches one row
  • GDataXML nodesForXPath on Node contains items of entire GDataXMLDocument
  • Ruby on Rails: After search, list not displaying all data
  • what's wrong with this Magento query?
  • How to add class on wp_list_pages children
  • Select Data After Specific Date
  • WordPress child nav a:current styling
  • jquery: ajax based search - browser crash?
  • Rails help ActionView::Template::Error HINT: No operator matches the given name and argument type(s
  • How to use custom customer variables in transactional email templates in magento?
  • Detect if Junit test class is running in a suite or alone
  • Using list comprehension instead of for loop when working with Django QuerySets
  • How to skip require in ruby?
  • Add dynamic data to line chart from mysql database with highcharts
  • Using Sax parsing to edit and write XML in VB6
  • HTTP/2 streams vs HTTP/1.1 connections
  • Syntax for setting draggablecursor property in google maps api
  • Using $this when not in object context
  • Read text file and split every line in MSBuild
  • Fetching methods from BroadcastReceiver to update UI
  • WinForms: two way TextBox problem
  • Fill an image in a square container while keeping aspect ratio
  • Join two tables and save into third-sql
  • Convert array of 8 bytes to signed long in C++
  • GridView Sorting works once only
  • How to get icons for entities from eclipse?
  • Understanding cpu registers
  • Recursive/Hierarchical Query Using Postgres
  • Running Map reduces the dimensions of the matrices
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?