Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter sandraqu

    (@sandraqu)

    anyone?

    I’m trying to use YOURLS to Twitter (WordPress plugin) to output the excerpt.

    The plugin’s instructions suggest

    %F{something}: custom post field ‘something’. See get_post_meta().

    WordPress informs

    <?php $meta_values = get_post_meta($post_id, $key, $single); ?>

    Where $key is a string “(required) A string containing the name of the meta value you want.”

    The HTML has

    <meta name="description" content="this is my excerpt" />

    Where the description meta has the excerpt’s content.

    I tried using

    #in %F{description} %U

    and got “#in bit.ly/7493d0e”. How can I get the excerpt to print? This is the php interpreting that %F

    if( preg_match_all( '/%F\{([^\}]+)\}/', $tweet, $matches ) ) {
        foreach( $matches[1] as $match ) {
            $field = get_post_meta( $id, $match, true );
            $tweet = str_replace('%F{'.$match.'}', $field, $tweet);
    
        }
        unset( $matches );
    }
    Thread Starter sandraqu

    (@sandraqu)

    For anyone wanting to do this, here is what I did to get it working. If you can improve this, feel free. I’m not a lithe PHP Developer.

    I added this conditional into core.php about line 454.

    if (strpos($tweet, '%E') !== false) {
                // Get post excerpt
                $post = get_post( $id );
                $post_exc = $post->post_excerpt;
                unset( $post );
    
                // Replace %E with post excerpt
                $tweet = str_replace('%E', $post_exc, $tweet);
            }

    And, in WP, called %E in the Settings for YOURLS WordPress to Plugin Tweet message field: #in %E %U

    Obviously the “#in” is there so that the Tweet posts to LinkedIn.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: YOURLS: WordPress to Twitter] How do I post excert using %F{} ?’ is closed to new replies.