How to modify the Loop from a plugin (instead of a theme)

for a simple meta query you can do this: function wpa_47150( &$query ) { if(!is_admin()){ set_query_var(‘meta_key’, ‘test_field’); set_query_var(‘meta_value’,’bacon’); } } add_action(‘pre_get_posts’,’wpa_47150′); i wasn’t sure it was going to work, but apparently you can set the whole meta_query object this way too function wpa_47150( &$query ) { if(!is_admin() && is_post_type_archive( ‘test_post_type’ )){ $metaq = ( array … Read more

Detect category choice for posts with multiple categories

Use: get_query_var(‘category-name’); Which will give you: example.com/category/subcategory/my_post Which you can then put into any queries you make under category-name. You can see this in action using the Monkeyman rewrite analyser plugin, by entering one of the URLs for a post and seeing the query variables it generates using those rules

How do I include a template file while allowing it to render its own dynamic content added via custom box?

You can include any template you want using get_template_part() e.g.: <?php get_template_part(‘navigation’); ?> Using this function also gives you child/parent theme support. Also of note, you could put: <?php get_template_part(‘navigation’,’search’); ?> Which would attempt to load navigation-search.php, but if that isn’t found or doesn’t exist, it will fallback and load navigation.php instead. I use this … Read more

How do I add my PHP app to a WordPress page whilst keeping semantic URLs?

Its not good way to edit .htaccess for wordpress url rewriting (only for main urls settings from admin panel) You found your response here : API basic url rewriting or The Rewrite API: Post Types & Taxonomies An example : add_action( ‘init’, ‘rewrite_rule’ ); function rewrite_rule() { global $wp,$wp_rewrite; // Remember to flush the rules … Read more

Add custom fields to a page template, admin side

You can do this via JavaScript rather easily. Here are the steps you need to take. I’ve created a sample (untested) script below as a proof-of-concept for you. Register your meta box add_action(‘add_meta_boxes’, ‘foo_page_template_meta_box’); function foo_page_template_meta_box(){ add_meta_box( ‘foo_page_template_options’, __(‘Foo Page Template Options’), ‘foo_page_template_options’, ‘page’ ); } function foo_page_template_options(){ //Your custom field form goes here } … Read more