• Resolved Dana S

    (@dana-s)


    Hello,

    Wonderful plugin. I was wondering how I might go about adding the movie date in the title.

    For example, the movie “It Happened One Night” was released in 1934. I would like the title for that movie page (the post) to be “It Happened One Night 1934” automatically.

    I am willing to edit code myself to achieve this if you tell me what file and where to edit it.

    OR,

    If this task proves to me too hard, it’s worth noting that I am using WordPress SEO by Yoast. I can edit meta titles without messing with the actual post title. I just don’t know what to add in the feild.

    The default meta title feild in yoast (admin side) is:

    %%title%% %%page%% %%sep%% %%sitename%%

    I tried the following to get the date to show in the title. but to no avail:

    %%title%% %%page%% %%sep%% %%sitename%% %%ct_release_date%% %%tmdb_data_release_date%% %%release_date%% %%ct_release_date%%

    I hope you have a solution for me. Thanks and once again, wonderful plugin

    https://www.ads-software.com/plugins/wpmovielibrary/

Viewing 15 replies - 1 through 15 (of 17 total)
  • Hi Dana S,

    Now that’s a very interesting question! I’ve played a bit with that idea, actually you don’t even need to edit the plugin at all, a small block of code added to your theme’s functions.php file will do! See https://gist.github.com/CaerCam/969881392675790a5332

    I like the idea of using this along with the SEO by Yoast plugin, though I don’t know if it’s even possible. I’ll put some thinking into this ??

    Oh, and thanks for the kind words, means a lot!

    Thread Starter Dana S

    (@dana-s)

    thanks for your prompt response. I’m going over to check out the link reference now. Is there a way to access the movies year (release date) on pages other than single post? for example, I want to add the year under the movie post in the loop on the index page. To add a custom field to a movie on the index page, I would add something like this (<?php echo get_post_meta($post->ID, ‘custom_field’, true); ?>)

    to no avail, I tried:

    (<?php echo get_post_meta($post->ID, ‘release_date’, true); ?>)
    (<?php echo get_post_meta($post->ID, ‘movie_date’, true); ?>)
    (<?php echo get_post_meta($post->ID, ‘date’, true); ?>)
    etc,

    Thanks in advance. And thanks again for the fast response. I’m going over to check the github link now ??

    Thread Starter Dana S

    (@dana-s)

    Regarding “movie date in title”, I added the code to my themes functions as instructed at https://gist.github.com/CaerCam/969881392675790a5332, but it didn’t work. I deactivated yeast seo plugin, but that didn’t work either. I’ll keep fiddling with it. Thanks

    Thread Starter Dana S

    (@dana-s)

    BTW I tried updating a post and refreshing a number of times, but code at https://gist.github.com/CaerCam/969881392675790a5332 still didn’t work.

    Could be another plugin/theme interfering, I’ll investigate this. What theme are you using?

    About including meta, I’m afraid the current stable version is clearly outdated on that part… It’s doable, but really messy. We’re planning to release version 2.0 by the end of the month, which will include a major update of metadata and details handling. My advise is to wait a bit for that version to avoid having to update your site in a week or so ??

    A clue: could try editing the function and change $meta = get_post_meta( $post_id, '_wpmoly_movie_data', $single = true ); to $meta = get_post_meta( $post_id, '_wpml_movie_data', $single = true );?

    Thread Starter Dana S

    (@dana-s)

    Thanks very much ?? That did the trick, but it still behaves as a pseudo meta title, in that any plugin or code that reads the title picks up the title without the date included. Again I do appreciate your time and help.

    My next attempt at a solution, is just to find some way to attach the date to the titles in bulk, meaning the date is actually in the title.

    My first attempt was removing the follwing code:

    // Don’t do this in admin
    if ( is_admin() )
    return $title;

    This place the dates in the titles on the admin side. I got excited thinking I could bulk update the posts status at once (published>draft, draft>published) and the dates would really become part of the title, but that didnt work.

    Is there a way to get the code added to the functions to allow me to bulk update all posts, so that they include the date in their titles?

    Thanks again for everything.

    Ok, my bad, I didn’t realize you want to actually modify the title, I thought you were just trying to add the year dynamically.

    In that case you can bulk edit all movies using a small PHP script like this: https://gist.github.com/CaerCam/fab579c61eecb8d32d88 Place this file at the root of your WordPress folder, load it once in your browser and it should do the job.

    Note, you want to make a backup of your database before doing this. This script will basically batch edit all your movies title and update all your movies’ posts, so better have a backup in case anything goes wrong!

    Edit: in addition to that last statement, here’s a script to reverse the effects of the first one: https://gist.github.com/CaerCam/8ea93d1f97c4999f1bc1 Just in case ??

    Thread Starter Dana S

    (@dana-s)

    Thanks a million ?? That did the trick as I wanted. I would have preferred the dates to be like (YYYY) with parenthesis, as opposed to yyyy. But, I am elated with this solution. Thanks again for your wonderful contribution.

    You can easily adapt the script to have (YYYY) instead of yyyy, but I guess that’s too late already ??

    The only thing to add is that this modification won’t be active for the next movies you add/import, meaning you’ll have to manually edit the titles in the post editor to add the release date.

    Glad you got it to work anyway!

    Thread Starter Dana S

    (@dana-s)

    Thanks, I’m temped to play around with the code as I normally do to figure out how to add the parentheses around the year.

    I’m assuming the edit would be on line 25, but I don’t want to hit and miss until I get it right, since I would be making bulk edits to the database and I don’t want to mess anything up.

    I used the second script *https://gist.github.com/CaerCam/8ea93d1f97c4999f1bc1) to reverse the titles back to normal.

    I would like to wrap the parentheses around the year, so if you have time to tell me what I should edit in the code at (https://gist.github.com/CaerCam/fab579c61eecb8d32d88) to acheive (YYYY), I’d be very grateful.

    You’ve already exceeded my expectations. Thanks

    Easy, just replace line 30 with: $post->post_title = sprintf( '%s (%d)', $post->post_title, $date ); ??

    Thread Starter Dana S

    (@dana-s)

    Worked perfectly. Thanks again ??

    Marking as solved ??

    I’ve been scratching my head trying to append the year to titles properly in the theme for hours, then i remembered that there was something like this in here

    your code works like a charm, i had to change a little bit of it for 2.x
    here is the snippet: https://pastebin.com/Q7hYnu8Z

    probably needs some check of sorts, i dunno, but it works

    Merci Charlie ??

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘movie date in title’ is closed to new replies.