Hide post if matches current month and year

Initialize an array before the first loop: $exclude = array(); Then add the ID of each post within the first loop to that array: while ($query->have_posts()) { $query->the_post(); $exclude[] = get_the_ID(); // etc… Then use that array to exclude those IDs via post__not_in in the second query: $args = array( ‘post_type’ => ‘page’, ‘post__not_in’ => … Read more

Trying to make php run in a post

Here’s a solution using a [shortcode] which doesn’t rely on running PHP inside of the content area. Here are the docs for get_post_meta() which show how that function should be called. add_shortcode( ‘buy_status’, ‘wpse249289_buy_status’ ); function wpse249289_buy_status( $atts ) { $output=””; if ( ! get_post_meta( get_the_ID(), ‘buy_status’, true ) ) { // Post meta value … Read more

PHP in post content [closed]

It was a stupid question, I just realized, if I just create a custom shortcode for it, the plugin will not wrap it in <p> tags then, or even better still just create it as a plugin of it’s own.

Auto crop images in WordPress

You can use add_image_size to create your custom size like this: add_image_size( ‘featured-works’, 220, 180, true ); then get it like this: wp_get_attachment_image_src($thumbnail_id,’featured-works’); take into account how the crop works here

Insert array data on plugin activation

You may please use this code that will help you to insert data into database register_activation_hook( __FILE__, ‘my_plugin_create_db’ ); function my_plugin_create_db() { global $wpdb; $table_name1 = $wpdb->prefix . “woo_currency”; $curr_name = array(‘Dollars’, ‘Ruble’, ‘Riel’); $curr_symbol = array(‘$’, ‘p.’, ‘៛’); $insert = $wpdb->insert($table_name1, array( ‘name’ => $curr_name, ‘symbol’ => $curr_symbol, ),array(‘%s’, ‘%s’)); } Hope this will … Read more

Displaying a button on each post

Use the_content hook and hook only when you are on a single page: add_filter( ‘the_content’, ‘my_button_function’ ); function my_button_function( $content ) { // See if it’s a single post or a loop if ( is_single() && in_the_loop() && is_main_query() ) { return $content . “<button onclick=\”buttonAction()\” p style=\”font-size:10px\” id=\”ActionButton\”>ACTION</button>”; } return $content; } This will … Read more

doing an ajax request always outputs 0

Your custom functions should always go in your theme’s functions.php file (if they are not within plugin territory). You should never try to modify any core files outside the wp-content folder (except wp-config.php) as they will be overridden by future updates. Now, there are 2 ways to do what you want. 1 – Admin-ajax This … Read more

Locating Global Variables

Child themes The WordPress Way of modifying the theme’s page-templates/front-page.php is to create a child theme, then duplicate this file in the child theme and make the modifications there. Your modified template file will be loaded instead of the parent theme’s file. This allows the parent theme to be updated without losing the modifications made … Read more

Loading header.php on specific page

Okay. I got it working. I just had to create a copy of the header.php in my child theme, rename it and add if(is_page(XXXX)) { get_header(‘header-name’); } else { get_header(); } after the initial <?php in the page.php of my child theme.