Advertisement in Loop Posts wordpress

Use WP_Query and then loop the results using break when you want to stop to put the ad. $args = [ ‘posts_per_page’ => 5 ]; $posts = new WP_Query($args); Then loop 2 <section class=”posts”> <?php $cont = 0; ?> <?php while( $posts->have_posts() ) : $posts->the_post(); $cont++; $id = get_the_ID(); //Show your post here if($cont >= … Read more

ajax polling with admin-ajax.php

You idea is equivalent to DDOSing your site, and the difference between the methods is only how fast you will bring the site down. WordPress AJAX handling is expensive, and should be limited to user initiated actions. Your second method will be more resilient but you are still going to be wasting server resources as … Read more

Get field in readable word

(Updated/new answer) How to make it show “United States (US)” instead, on the frontend, in a shortcode? First off, you got united-states (the country slug/key) instead of United States (US) (the country name) because your extrainfo_save_extra_user_profile_fields() function is saving the country slug/key instead of the country name. That’s not a problem, and I’d do the … Read more

Using wordpress functions in class and change my code to OOP PHP

Thank you guys for all the suggestions and answers. I have fixed it, see my code below: class advanza_form { // Class properties defined using PHP Coding Guidelines and taking security measures: http://www.php.net/manual/en/language.oop5.visibility.php public $site_id; public $affiliate_id; public $redirection; protected $url; private $response; private $header; // For debugging public $status_code; // For debugging public function … Read more

Grouping posts by date

<?php $day_check = ”; while (have_posts()) : the_post(); $day = get_the_date(‘j’); if ($day != $day_check) { if ($day_check != ”) { echo ‘</ul>’; // close the list here } echo get_the_date() . ‘<ul>’; } ?> <li><a href=”#”><?php the_time(); ?><?php the_title(); ?></a></li> <?php $day_check = $day; endwhile; ?> do like this i hop this work

Having issue on Loading Meta Data From CSV to CPT

Your metas need to be passed to wp_insert_post() as an array like so: // Insert the post into the database $post[“id”] = wp_insert_post( array( “post_title” => $post[“title”], “post_type” => $cpt[“custom-post-type”], “meta_input” => array( “custom-field-1” =>$cpt[“custom-field-1”], “custom-field-2” =>$cpt[“custom-field-2”], ) “post_status” => “publish” )); https://developer.wordpress.org/reference/functions/wp_insert_post/#parameters

WP Plugin permissions – create new files

I can think here of two possibillites. Use the wp-content/uploads maybe for your text-file because the file permission restriction are more or less bypassed in this directory. Put all stuff to wp_options and write a page Template imitating the text-file like page_text.php /* Template Name: Text-Template */ echo get_option(‘ads’, false); Create a page and asign … Read more