WordPress archives by custom field and date

This will get the posts filtered by custom field and its value based on categories. $args = array( ‘post_type’=>’post’, ‘category__in’=> array(6, 7, 31), //category id ‘meta_key’=>’keys’, // customfield name ‘meta_value’=>5, // customfield value ‘posts_per_page’=>-1, ‘number_posts’=>-1 ); $s = get_posts($args); foreach($s as $e ) { echo $e->ID.'<br/>’; echo $e->post_title.'<br/>’; }

How to overwrite a value for a custom field?

I don’t think the problem is with the workings of the custom meta field (look into the XY problem). The issue is with the use of relative URLs, whether you realize that that is what you are doing or not. Left empty, <a href=”” target=”_blank”> is by default the page you are on. Likewise, echo … Read more

Custom classes for attachments

Just add the following code in functions.php file of your theme which will add your custom added classes to images when you will insert it into post editor. function add_image_class($html, $id, $caption, $title, $align, $url, $size, $alt=”” ){ $classes = get_post_meta( $id, ‘classes’, true ); if ( preg_match(‘/<img.*? class=”.*?”>/’, $html) ) { $html = preg_replace(‘/(<img.*? … Read more

Change event firing in wordpress

Using transistion_post_status I’m able to retrieve post meta. add_action( ‘transition_post_status’, ‘post_published’, 10, 3 ); function post_published( $new_status, $old_status, $post ) { if ( $old_status != ‘publish’ && $new_status == ‘publish’ ) { $meta = get_post_meta($post->ID); echo ‘<pre>’; var_dump($meta); echo ‘</pre>’; die(); } }

How to keep sharing stats after creating 301 redirects?

Got it. I was already using the Advanced Custom Fields plugin so I just created a custom field called “old_url” with that. Then I created a function: function sharingurl () { if(get_field(‘old_url’) == “”) { echo untrailingslashit(get_permalink()); } else { echo get_field(‘old_url’); } } Then I just included <?php sharingurl(); ?> in the data-href and … Read more

Can i categorise my meta box?

The code you posted in your question is very very very incomplete, anyway I will try to give you an answer. You can define as many meta box as you need and put inside each meta box the fields you want. For example: add_action( ‘add_meta_boxes’, ‘my_meta_boxes’ ); function my_meta_boxes(){ //We define the two metaboxes I … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)