Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:22:48+00:00 2026-06-18T08:22:48+00:00

I have a function in my WordPress theme functions.php file with the following code:

  • 0

I have a function in my WordPress theme functions.php file with the following code:

function locations() {
    $locations_list = array();
    query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'post_type' => 'location'));
    while(have_posts()) {
      $locations_list[the_slug()] = the_title();
    }
    wp_reset_query();
    return $locations_list;
}

The idea is that I can run this function anywhere on my site and it will store all my posts in an array.

However, I have no idea how I run this at the public end :'(

Perfect world, I’d like to run this in my footer.php script.

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:22:48+00:00Added an answer on June 18, 2026 at 8:22 am

    Perfect world, I’d like to run this in my footer.php script.

    Then simply run the function in the footer.php template from your theme.

    Also, avoid using query_posts() for custom queries because that function alters the main query. Use the WP_Query class directly instead:

    $query = new WP_Query(array(...));
    while($query->have_posts()) {
      $query->the_post();
      // $locations...
    }
    

    FYI the_title() prints the post title on the screen, so you don’t need to assign it to a variable because it returns nothing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried the following code in a template file of wordpress. <?php query_posts('showposts=9&post_type=packages&packages_category='.$category.'&order=ASC&paged='.$paged);
So, I have a Wordpress theme. In the functions.php file, I'm writing a function
I have defined the following function in my Wordpress site's functions.php file, it should
this is function.php of a wordpress theme that NOD32 says this code have a
I have created the below function in wordpress in my themes functions.php file. I
I have a problem with my wordpress theme, the functions.php file ouputs ome bad
Wordpress themes have standard file such as header.php, footer.php, index.php, functions.php, style.css, ... How
I have a function in a functions.php file that defines certain variables: add_action( 'the_post',
I'm editing the functions.php file of a WordPress theme and whenever I edit it,
I have the following code which I would like to implement in my Wordpress

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.