简体   繁体   English

WP按标题获取具有数组值的函数

[英]WP get page by title function with array values

I'm trying to use WP function get_page_by_title for getting page ID by its title, and using this code, 我正在尝试使用WP函数get_page_by_title通过标题获取页面ID,并使用此代码,

$page = get_page_by_title("page name" 'OBJECT', 'post_type');

It works fine if we pass a single page name, but I need to get id's from multiple pages for instance, I've an array ( $tenders ) which holds the selected pages name and I need to pass similar as below 如果我们传递单个页面名称,则可以正常工作,但是例如,我需要从多个页面获取ID,我有一个数组( $tenders ),其中保存了选定的页面名称,我需要像下面这样传递

$page = get_page_by_title($tenders, 'OBJECT', 'post_type');

It doesn't work at all for some reason! 由于某种原因,它根本不起作用! I spent lot of time for suitable solution but in vain. 我花了很多时间来寻找合适的解决方案,但徒劳无功。 Any quick fix for this issue would be highly appreciated. 任何快速解决此问题的方法将不胜感激。

You can get the ID's with foreach loop. 您可以使用foreach循环获取ID

Let suppose you have an array of page titles. 假设您有一组页面标题。

$tenders = array( "page One", "Page Two", "Page Three" );

foreach ( $tenders as $tender ) {
  $page = get_page_by_title( $tender, 'OBJECT', 'post_type' );
  // see the ID
  echo $page;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM