use advance custom field inside query post command [closed]

When you do this:

<?php query_posts('category_name=<?php the_field('cat_1_name'); ?>','showposts=5'); ?>

The string argument is literally category_name=<?php the_field('cat_1_name'); ?>','showposts=5. Well, it would be if the string were not also triggering a fatal error.

What you have is (assuming I haven’t lost track of the mess):

  • String 1: 'category_name=<?php the_field('cat_1_name');
    ?>','showposts=5'
  • An undefined constant: cat_1_name
  • An out of place comma, making what follows a second argument to a
    function that only takes one argument: ,
  • And String 2: 'showposts=5'

That is never going to work. If you are going to be writing code you need to learn to create strings in PHP. That has got to be in the first five things you should learn to do well.

Secondly, you are not in HTML context so you do not need to be using PHP open and close tags at all, and doing so will trigger further fatal errors.

Third, you are mixing up array syntax with the hard-to-read-and-hard-to-edit-and-prone-to-error query-string-like syntax that is mysteriously popular in WordPress.

Fourth, AFC’s the_field echos content. You can’t use that to concatenate a string anyway. You need get_field.

Fifth, showposts has been deprecated for a very long time. Use posts_per_page.

Strings that should work:

"category_name=".get_field('cat_1_name')."&posts_per_page=5"
'category_name=".get_field("cat_1_name').'&posts_per_page=5'

But don’t use that query-string syntax, create an array.

$args = array(
  'category_name' => get_field('cat_1_name'),
  'posts_per_page' => 5
);

And finally, please don’t use query_posts.

It should be noted that using this to replace the main query on a page
can increase page loading times, in worst case scenarios more than
doubling the amount of work needed or more
. While easy to use, the
function is also prone to confusion and problems later on. See the
note further below on caveats for details.

http://codex.wordpress.org/Function_Reference/query_posts (emphasis mine)