using query_posts() and custom_fields.
-
I am new to wordpress but not new to scripting and code.
I need to get the value from a page’s custom field into a query_posts() of a page template.I needed a way to add posts to a static page so I created a custom page template based off of page.php. it’s called articles-page.php. In this custom template I added the following code AFTER the loop that appears to print the contents of the page.
<?php global $more; $more = 0; query_posts('cat=5'); if(have_posts()) : while(have_posts()) :the_post(); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h2> <div><?php the_content('Read More') ?></div> <?php endwhile; endif; wp_reset_query();?>
This is currently working. I have my page’s content and it is followed by posts that have ‘cat=5’. However I want versatility so I can apply this custom template to multiple pages (each with different $args i want to pass to query_posts()). Inside each page is a “custom fields” tab. For each page I have a custom field who’s name is “query_args” and their value is a string/array I want to pass to the query_posts() in the code above.
What would I need to replace the ‘cat=5’ with in my code above, so that it will read the value of ‘query_args’ from the custom field that is defined for that page?
Website: (News Page) https://www.TheChosenRPG.com
I am using wordpress 3.5.1. with sliding door theme
- The topic ‘using query_posts() and custom_fields.’ is closed to new replies.