Custom php file in wordpress

Andrew Bartel is on the right path, but the link doesn’t quite do what you want. For static PHP files to access WordPress core functionality you need to add this to the top of the PHP file: define(‘WP_USE_THEMES’, true); /** Loads the WordPress Environment and Template */ require( dirname( __FILE__ ) . ‘/wp-blog-header.php’ ); (This … Read more

Problem getting single_template filter to work – I want to serve a different single.php file for posts in a certain category

The problem was that the remove_filter function wasn’t working. Apparently this is not uncommon from what I’ve read. I tried testing it with different priorities (1, 9, 20, 999), but there was no difference. So my filter in the child theme and the filter I was trying to remove from the parent theme both had … Read more

how to redirect to my template

Actually you can overwrite get_page_template() using page_template filter. So now, your code should be like bellow code. add_filter( ‘page_template’, ‘load_template_from_plugin’ ); function load_template_from_plugin( $page_template ){ if ( is_page( ‘bog_test’ ) ) { $page_template = dirname( __FILE__ ) . ‘/bog_test.php’; } return $page_template; } Try the above code then let me know the result. Thanks

How to properly use a hook to create template for custom product type in a plugin such as Woocommerce? [closed]

You may use an action in the format woocommerce_YOUR_PRODUCT_TYPE_add_to_cart to reach the goal. Here is the example. The following code is for putting in functions.php, if you are writing a plugin. Please remember to change the callback. eg. you have a product type called Special, you want to add the add-to-cart template for it. add … Read more

Prevent private post 404

According to the Content Visibility page, Private posts are visible only to those with sufficient permission levels. WordPress doesn’t expose them to non-logged-in users at all, hence (presumably) the 404. If you want to display a limited preview to non-members, instead of setting the post to Private, you could try something like this: add_filter( ‘the_content’, … Read more

Modifying searchform.php and search.php to have two kinds of searches

For anyone trying to achieve something similar, here’s how I solved it: In searchform.php, duplicate the form, as such: <form method=”get” id=”searchform” action=”<?php echo esc_url( home_url( “https://wordpress.stackexchange.com/” ) ); ?>”> <input type=”text” name=”s” id=”s” placeholder=”<?php esc_attr_e( ‘Search by Post’ ); ?>” /> <input type=”hidden” name=”search-type” value=”posts” /> <button type=”submit” name=”submit” id=”searchsubmit” value=”<?php esc_attr_e( ‘Search’ ); … Read more

how to show all post in my page-grid.php template page

<?php $args = array( ‘post_type’ => ‘put your custom PostType name here’, ‘posts_per_page’ => ‘-1’ ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); // Contents of the queried post results go here. } } // Restore original post data. wp_reset_postdata(); ?>