2

So I am interested in allowing a custom menu to show "in three places: Menu area, Homepage body, and footer" based on the posttype "page" table list or parent and children entries and not using the WP nav menu system.

Reason is, I want users to control the menus displaying of my site using custom fields on each page. All 3 menus on the site will parent titles (w/ children page titles in the header menu only), but all with "different styling" done to each of the 3 sections.

I will make the function a shortcode [mycustommenu area="header"] which will allow me to pass "header" attribute into my function.

So my questions are:

Should I use WP_Query OR the get_posts / get_children function for this?

Should I run multiple loops separated by if statements if(atts['header']): or should I just do 1 loop and separate the object->results with the if statements?

Just looking for the best solution in terms of optimization. And IF there is a better way to do this all together, please let me know :)

  • 1
    WP_Queryis the better route 9/10 times, with the exception of a wp_admin_json response. I'd also recommend using the following to manage the query function manage_query($wp_query){var_export($wp_query);exit;/*your code goes here*/}add_action('pre_get_posts','manage_query'); – admcfajn Mar 15 '18 at 17:43
  • Thanks for your response! So I'm trying to understand using pre_get_posts.... Am I trying to change an establish query somewhere? And when you say /*your code here*/ Are you saying to add the get_children function there. Please elaborate. – samjco Mar 16 '18 at 4:15
  • So to build a different query for each area? How would I style results? And how would I get children within each query? Please elaborate more. – samjco Mar 16 '18 at 4:30
  • My comment may not be relevant. Could you please provide read the following & update your question with example of the code? I'm finding it a little hard to figure out what you're asking: stackoverflow.com/help/mcve to get child-pages you'd query for post-type page where parent=ID_of_parent. This should help you understand wp-query vs get_posts a bit better: wordpress.stackexchange.com/questions/1753/… – admcfajn Mar 16 '18 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.