How to store queried custom data and use it in multiple pages?

Though it’s not clear exactly what do you want. But, you can do this by two ways. Make a Function like function wpse_1001(){ $contact = new WP_Query(array( ‘post_type’ => ‘contact’ // ‘post_status’ => ‘publish’ )); while($contact -> have_posts()){ $contact -> the_post(); $watsapp = get_field(‘watsapp_no’); $mobile = get_field(‘mobile_no’); $telephone = get_field(‘telephone_no’); $address = get_field(‘address’); } wp_reset_query(); … Read more

Add HTML before a specific div?

Seems like jQuery is best for this case. Mainly answering for myself in case I’ll need it again in the future: <head> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> <script> $(document).ready(function(){ $(“#this_comes_before”).insertBefore(“#wc_checkout_add_ons”); }); </script> </head> <body> <div id=”wc_checkout_add_ons”>stuff</div> <div id=”this_comes_before”>something</div> </body> Edit for future me: Use this instead you lazy asshole… add_action( ‘woocommerce_checkout_after_customer_details’, ‘test99’ ); function test99() { echo “your … Read more

Two post types with same single template

The other option would be to create the template as a Page Template, and have both CPTs support page-attributes so they can then use Page Templates. Typically you name the template something like tpl-yourname.php and it would contain a comment at the top: <?php /* * Template Name: Your Name * Template Post Type: cpt-slug-a, … Read more

how to pass args for archive.php query?

The pre_get_posts hook can be used to modify queries before they’re run. You can use $query->set() to set arguments on the WP_Query object, and $query->is_main_query() in the callback to limit your changes to the main query: add_action( ‘pre_get_posts’, function( $query ) { if ( ! is_admin() && $query->is_main_query() ) { $query->set( ‘posts_per_page’, 12 ); } … Read more