Wordpress - How to Get the Value of Custom Fields in the Theme

Asked

Viewed 207 times

0

Personal talk!

I am beginner in Wordpress and I came across a problem.

I’m trying to get the value of a Custom Field that has in wp-admin called Client Link, there in the site plugin in the metaboxes statement, is stated as follows:

$metaboxes[] = array(

            'id'            => 'detalhesMetaboxCliente',
            'title'         => 'Detalhe do cliente',
            'pages'         => array( 'cliente' ),
            'context'       => 'normal',
            'priority'      => 'high',
            'autosave'      => false,
            'fields'        => array(

                array(
                    'name'  => 'Link do cliente: ',
                    'id'    => "{$prefix}cliente_link",
                    'desc'  => '',
                    'type'  => 'text'
                ),

            ),

        );

And the in the theme, to search the registered Client, is like this:

$clientePost = new WP_Query( array( 'post_type' => 'cliente', 'orderby' => 'id', 'order' => 'asc', 'posts_per_page' => 0 ) );

while ( $clientePost->have_posts() ) : $clientePost->the_post();
   // pega a foto do cliente
   $foto = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
   $foto = $foto[0];
   // pega o link
   $link = get_post_meta($post->ID, 'Maiacliente_link', true);
   echo $link;
endwhile; wp_reset_query();

The problem is that I’m not getting the link, the value is coming empty. What I’m doing wrong?

  • See if you have any meta value associated with your post. Call get_post_meta with a var_dump: var_dump(get_post_meta($post->ID))

  • I found it, it was Maia_cliente_link and not Maiacliente_link

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.