带数字的自定义 post 类型的条件标记的正则表达式

Regex for conditional tag for a custom post type with numbers

我正在使用创建问题页面的插件。每个页面的 URL 如下所示: example.com/?question_441

我想向所有问题页面添加一个操作,我正在尝试使用条件标签来实现。 以下条件标签专门用于 question_441:

if ('question_441' == get_post_type())

但是,我希望它适用于所有问题页面。我尝试了以下方法:

if ('question_'.'[0-9]' == get_post_type())

但这行不通。谁能告诉我正确的连接和正则表达式。 谢谢:-)

我想你正在寻找这个:

if (preg_match('/question\_[0-9]+/', get_post_type()))