Rename file after title , one small problem

Use get_the_title() since you’re already being passed a post ID. function rename_attacment( $post_ID ) { $post = get_post( $post_ID ); $file = get_attached_file( $post_ID ); $path = pathinfo( $file ); //dirname = File Path //basename = Filename.Extension //extension = Extension //filename = Filename $newfilename = get_the_title( $post_ID ); $newfile = $path[‘dirname’] . “https://wordpress.stackexchange.com/” . $newfilename … Read more

WordPress loop put title into variable

Creating variables on the fly like that is not needed. Just use an array instead. $myvars = []; inside your foreach loop you can: $myvars[] = array(‘title’=>$t,’image’=>$v); After your loop you can: //First title, First image echo $myvars[0][‘title’]; echo $myvars[0][‘image’]; //Second title, Second image echo $myvars[1][‘title’]; echo $myvars[1][‘image’]; This way you can always print_r($myvars) and … Read more

Bug with post titles [closed]

This is usually due to using custom query/loop stuff after the main query and not calling either wp_reset_postdata() or wp_reset_query() after you’re done. See this answer for more detail on which to use.

Why this Read More Not working in Php?

EDIT Based on your last concern, here how I would do this. The only problem left on your code is that you are calling some HTML inside PHP without `echo. So I split all those into seperates HTML tags and called them separatly in PHP. <?php while(have_posts()): the_post(); ?> <h2><?php the_title(); ?></h2> <figure class=”thubmnail”> <?php … Read more

How to get all post titles starting with numbers and symbols?

Hook into the posts_where filter and add your condition to the query: add_filter(‘posts_where’, function($where){ global $wpdb; return “{$where} AND {$wpdb->posts}.post_title REGEXP ‘^[0-9\$\@\!\?\%]'”; // add other symbols in the regex above ^ }); Then do your query: $my_query = new WP_Query(…); You may want to remove the filter after you get the results (make it a … Read more

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