开发者

Wordpress SQL query: get random child page

开发者 https://www.devze.com 2023-01-12 11:31 出处:网络
I want my site to have a random \"welcome\" page. I\'ve found a plugin that redirects to a random page. I want to specify a parent page that random child pages are selected from.

I want my site to have a random "welcome" page.

I've found a plugin that redirects to a random page. I want to specify a parent page that random child pages are selected from.

This is the query that the plug-in uses:

$query = "SELECT ID FROM $wpdb-&g开发者_如何学运维t;posts WHERE post_type = 'page' AND post_password = '' AND post_status = 'publish' ORDER BY RAND() LIMIT 1";

How would I get it to return a random child page from a specific parent page?

Thanks for looking.


So simple I missed it. Just add AND post_parent='42' where 42 is your parent's ID.

0

精彩评论

暂无评论...
验证码 换一张
取 消