WordPress.org

Ready to get started?Download WordPress

Forums

TPG Get Posts
[resolved] Apply title/content filters (9 posts)

  1. Collin Donahue-Oponski
    Member
    Posted 2 years ago #

    Hi Criss,

    Would it be possible to get the title and content filters applied to the post before displaying it? Thank you for a great plugin!

    http://wordpress.org/extend/plugins/tpg-get-posts/

  2. Collin Donahue-Oponski
    Member
    Posted 2 years ago #

    My temporary fix is to change this (in tpg-get-posts/inc/tpg-gp-process.class.php):

    switch ($field) {
    					case "post_title":
    						$wkcontent = ($short_title)? $this->shorten_text($st_style,$st_len,$wkcontent,$this->ellip): $wkcontent;

    to this:

    switch ($field) {
    					case "post_title":
    						$wkcontent = ($short_title)? $this->shorten_text($st_style,$st_len,get_the_title(),$this->ellip): get_the_title();
  3. cswaim
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks for the code sample. I will look at adding this - but will need to test to see how it changes the existing output. I don't want to roll out a change that breaks existing designs. Is there a particular reason to use this function instead of the title text?

  4. Collin Donahue-Oponski
    Member
    Posted 2 years ago #

    I can't imagine it breaking anything, because the normal blog output would have these filters applied. But to avoid the chance of breaking anything, you could offer it as an option: apply_filters="true" with the default as "false".

    The only reason I can think of is the same reason title filters exist in the first place. Sometimes themes or plugins want to modify or add to the title or content before it is output. I believe there are even default WP filters (to do things like replace (tm) with ™) according to the last example of the apply_filters docs.

    The code I posted might not be the best solution. It might be better to use apply_filters directly... maybe you wouldn't have to hardcode every filter since you already have the $field variable with the name of the field. Here's a list of filters: http://codex.wordpress.org/Plugin_API/Filter_Reference

    You could probably get pretty far by doing a str_replace('post', 'the', $field) and passing that as the $tag for apply_filters.

  5. cswaim
    Member
    Plugin Author

    Posted 2 years ago #

    Collin:

    Thanks for the response. I remember adding the filter to the content a couple of revision back and I did not think about the title. I like your solution as it uses the standard wp processes and will incorporate it the next release. Agreed, it should not alter the display.

    Are you applying any content filters and are they working? Testing is the largest portion of the applying some of these fixes. I desk checked the code for the content and it is applying the filters, but not sure I have really done any specific tests to verify it works as planned.

    If the content looks good, then I will push out the change this weekend.

    Thanks again....Criss

  6. Collin Donahue-Oponski
    Member
    Posted 2 years ago #

    That would be awesome, thank you!

    I haven't tried it with the content filter on my site, because I only needed the title filter for now. You could try a simple filter for testing:

    add_action('wp', 'my_attach_test_filters');
    function my_attach_test_filters() {
        add_filter('the_title', 'my_test_filter');
        add_filter('the_content', 'my_test_filter');
    }
    function my_test_filter($content) {
        return "Filtered: " . $content;
    }
  7. cswaim
    Member
    Plugin Author

    Posted 2 years ago #

    I did think of a reason to not use the get_the_title. The routine to shorten the title counts characters and that needs to be done before applying the filters as I did with the content. So, a bit more testing.

    I will set up a test and see how it goes -- should get this out late today or tomorrow.

    Thanks again for the code & ideas.

  8. Collin Donahue-Oponski
    Member
    Posted 2 years ago #

    Looking forward to it. Thanks so much for being so responsive!

  9. cswaim
    Member
    Plugin Author

    Posted 2 years ago #

    1.3.6 is available.

    You caught me between jobs, so I had the time to look at this.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic