Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

112
Visualizações
Match string in shortcode using regex

I have this shortcode in my page content in Wordpress. I need to get the value of "layout" and the value from "slug"

So I need the values: listing & aircraft extracted from the string

I am looking for the lowest possible hit to performance. I am trying to get these values from the save_post hook so I don't have access to the normal shortcode $atts parameter.

'[vc_row][vc_column width="2/3"]

[cpt_categories layout="listing" view="grid" items_per_row="4" orderby="title" order="ASC" slug="aircraft"]

[/vc_column][vc_column width="1/3"][/vc_column][/vc_row]'

When using the native WP function shortcode_parse_atts I get close but there are some issues:

$atts = shortcode_parse_atts($post->post_content);
var_dump($atts);
array 
  0 =>  '[vc_row][vc_column' 
  1 =>  'width="2/3"][cpt_categories' 
  'layout' =>  'listing' 
  'view'   =>  'grid' 
  'items_per_row' =>  '4' 
  'orderby' =>  'title' 
  'order' =>  'ASC' 
  2 =>  'slug="aircraft"][/vc_column][vc_column' 
  3 =>  'width="1/3"][/vc_column][/vc_row]' 
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If those two values are literally all you need, then Regex could be a reasonable solution here. (just be careful about the whole "hammer and nails" thing with Regex and HTML)

Match group 1 in layout="([^"]*)" will get you the listing value.

Match group 1 in slug="([^"]*)" will get you the aircraft value.

They both work on your example string (as tested at https://regex101.com/).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda