Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author miunosoft

    (@miunosoft)

    Try this.

    <?php
    	$_sPostTitle = is_single() ? single_post_title( '', false ) : wp_title( '', false );
    	$_sPostTitle = str_replace( 'ENTER THE REPLECEMENT TEXT HERE', '', $_sPostTitle );
    	fetchTweets( array( 'q' => $_sPostTitle, 'lang' => 'en' ) );
    ?>

    Replace the part ENTER THE REPLECEMENT TEXT HERE to your desired text.

    Thread Starter michaelwe

    (@michaelwe)

    not works…

    can you cut the code before first dot?

    Plugin Author miunosoft

    (@miunosoft)

    With your given sample string, the code should look like,

    <?php
    	$_sPostTitle = is_single() ? single_post_title( '', false ) : wp_title( '', false );
    	$_sPostTitle = str_replace( ".aaa bbb - home", '', $_sPostTitle );
    	fetchTweets( array( 'q' => $_sPostTitle, 'lang' => 'en' ) );
    ?>

    You see where you need to modify. You need to put the replacement string that you don’t need in the str_replace() PHP function (the first parameter).

    Thread Starter michaelwe

    (@michaelwe)

    yep,
    I have replace it

    this one should be the whole title in <title></title>
    <?php fetchTweets( array( 'q' => is_single() ? single_post_title( '', false ) : wp_title( '', false ), 'lang' => 'en' ) ); ?>

    and this is what I do

    <?php
    	$_sPostTitle = is_single() ? single_post_title( '', false ) : wp_title( '', false );
    	$_sPostTitle = str_replace( ".aaa bbb - home", '', $_sPostTitle );
    	fetchTweets( array( 'q' => $_sPostTitle, 'lang' => 'en' ) );
    ?>

    But the result is the same!

    Plugin Author miunosoft

    (@miunosoft)

    You need to change the part ".aaa bbb - home" to your desired string to cut off. (Don’t forget to enclose it with quotes.)

    Thread Starter michaelwe

    (@michaelwe)

    I find it!
    single_post_title must be the xxx.aaa bbb

    so

    I replace the bbb with “”

    and works!

    can I replace more?
    do I just add line
    $_sPostTitle = str_replace( “ccc”, ”, $_sPostTitle );
    $_sPostTitle = str_replace( “ddd”, ”, $_sPostTitle );

    will they works?

    Plugin Author miunosoft

    (@miunosoft)

    Your code won’t work. Change the second line of my previous code as follows.

    $_sPostTitle = str_replace( array( 'first replacement item', 'second replacement', 'third', 'fourth', 'fifth' ), '', $_sPostTitle );

    And put your desired replacement strings in to the array() function. You can put as many items as you want.

    Thread Starter michaelwe

    (@michaelwe)

    awesome!
    works!

    which type of tweets fetched with the code you write?
    mixed – includes both popular and real time results in the response.
    recent – returns only the most recent results in the response.
    popular – return only the most popular results in the response.

    Plugin Author miunosoft

    (@miunosoft)

    By default, mixed is used. To specify the result type, change the fetchTweets() function call like this,

    fetchTweets( array( 'q' => $_sPostTitle, 'lang' => 'en', 'result_type' => 'recent' ) );

    Either mixed, recent, or popular can be set to the result_type option.

    Thread Starter michaelwe

    (@michaelwe)

    thank you very much, by the way I am very like Japan!

    Plugin Author miunosoft

    (@miunosoft)

    Haha, you are welcome!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How to cut off Search Title code?’ is closed to new replies.