Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda