Title: mattspace's Replies | WordPress.org

---

# mattspace

  [  ](https://wordpress.org/support/users/mattspace/)

 *   [Profile](https://wordpress.org/support/users/mattspace/)
 *   [Topics Started](https://wordpress.org/support/users/mattspace/topics/)
 *   [Replies Created](https://wordpress.org/support/users/mattspace/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/mattspace/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/mattspace/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/mattspace/engagements/)
 *   [Favorites](https://wordpress.org/support/users/mattspace/favorites/)

 Search replies:

## Forum Replies Created

Viewing 15 replies - 1 through 15 (of 28 total)

1 [2](https://wordpress.org/support/users/mattspace/replies/page/2/?output_format=md)
[→](https://wordpress.org/support/users/mattspace/replies/page/2/?output_format=md)

 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Set category (and its RSS feed) to display in descending, modified order](https://wordpress.org/support/topic/set-category-and-its-rss-feed-to-display-in-descending-modified-order/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [3 months, 3 weeks ago](https://wordpress.org/support/topic/set-category-and-its-rss-feed-to-display-in-descending-modified-order/#post-18884476)
 * Right, so we have the ability to **not** everything as a filter to leave the 
   thing we want, but lack the ability to specify the thing we want from the outset?
 * If you wouldn’t mind, would you set out the combined version with the ORs, so
   I can see what the syntax difference is?
 * thanks.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Set category (and its RSS feed) to display in descending, modified order](https://wordpress.org/support/topic/set-category-and-its-rss-feed-to-display-in-descending-modified-order/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [3 months, 3 weeks ago](https://wordpress.org/support/topic/set-category-and-its-rss-feed-to-display-in-descending-modified-order/#post-18884459)
 * [@threadi](https://wordpress.org/support/users/threadi/)
 * I tried your code example:
 *     ```wp-block-code
       function custom_sort_for_post_archive( $query ) {    // ignore in the backend.    if( is_admin() ) {        return $query;    }    // ignore if this is not the main query.    if( ! $query->is_main_query() ) {        return $query;    }    // ignore if this is not an archive.    if( ! $query->is_archive() ) {        return $query;    }    // ignore it if this is not the category.    if( 'photostream' !== $query->query_vars['category_name'] ) {        return $query;    }    // change the sort to order by modified date.    $query->set('orderby', 'post_modified');    // always return    return $query;}add_action( 'pre_get_posts', 'custom_sort_for_post_archive' );
       ```
   
 * …and it seems to be working as desired. If I look at the RSS feed, it’s showing
   the posts in the order I want. Small snag was encountered though, as it seems
   my RSS reader app insists on sorting things by strict publication date.
 * Does this function going through all these **if not** steps add an overhead to
   each page load on the site, that I might have avoided by just making a custom
   template .php file for the photostream category?
 * thanks.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Set category (and its RSS feed) to display in descending, modified order](https://wordpress.org/support/topic/set-category-and-its-rss-feed-to-display-in-descending-modified-order/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [3 months, 3 weeks ago](https://wordpress.org/support/topic/set-category-and-its-rss-feed-to-display-in-descending-modified-order/#post-18884261)
 * That’s interesting, when you say the ID isn’t available, I have functions that
   remove post categories from both the home page, and the RSS feed, and they target
   category IDs:
 *     ```wp-block-code
       // This function excludes posts of the diary categories from the home page feed	function mg_exclude_category_home( $query ) {	if ( $query->is_home ) {	$query->set( 'cat', '-97, -95, -93, -81, -80, -109, -112, -117, -123' );	}	return $query;	} add_filter( 'pre_get_posts', 'mg_exclude_category_home' );// This function excludes diary category posts from the RSS feedfunction exclude_category( $query ) {    if ( $query->is_feed ) {        $query->set('cat', '-97, -95, -93, -81, -80, -109, -112, -117, -123');    }return $query;}add_filter('pre_get_posts', 'exclude_category');
       ```
   
 * …but is the issue that the targeting of the function:
 *     ```wp-block-code
       if ( $query->is_home ) {
       ```
   
 * … or:
 *     ```wp-block-code
       if ( $query->is_feed ) {
       ```
   
 * …are specifically done with recognised fixed landmark targets hardcoded into 
   WP – home and feed. Is there not some equivalent for explicitly naming the category
   by name, slug, or ID? Something like:
 *     ```wp-block-code
       function custom_sort_for_photostream( $query ) { if ( $query->is_archive( 120 ) ) { // can we identify by ID or slug here ?// or should it use is_category ?// or is_whichever( 'cat', '120') ?        $query->set('orderby', 'post_modified');    }}add_action( 'pre_get_posts', 'custom_sort_for_photostream' );
       ```
   
 * …or is there another way to get the category id?
 * thanks – learning this stuff bit by bit.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Set category (and its RSS feed) to display in descending, modified order](https://wordpress.org/support/topic/set-category-and-its-rss-feed-to-display-in-descending-modified-order/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [3 months, 3 weeks ago](https://wordpress.org/support/topic/set-category-and-its-rss-feed-to-display-in-descending-modified-order/#post-18884214)
 * Thanks for that – so if I wanted to restrict this to a particular category’s 
   archive / feed, eg it only applies for the category ID 120, how do I add that
   specificity?
 * Is there a version of it that looks something like this:
 *     ```wp-block-code
       function custom_sort_for_photostream() { if( is_archive( 120 ) ) {        set('orderby', 'post_modified');    }}add_action( 'pre_get_posts', 'custom_sort_for_photostream' );
       ```
   
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Set category (and its RSS feed) to display in descending, modified order](https://wordpress.org/support/topic/set-category-and-its-rss-feed-to-display-in-descending-modified-order/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [3 months, 3 weeks ago](https://wordpress.org/support/topic/set-category-and-its-rss-feed-to-display-in-descending-modified-order/#post-18884112)
 * The **publish date** _IS_ being used for sorting. **That’s** the problem I’m 
   trying to solve.
 * I want it to order posts on the page, and in the feed for that category by **
   modified date**.
 * So a post I add _**today**_, with a published date of **last year**, shows up
   as more recent than a post I added **_last week_**, with a published date of **
   last month**.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Remote parent theme (absolute or relative paths)?](https://wordpress.org/support/topic/remote-parent-theme-absolute-or-relative-paths/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [8 months, 3 weeks ago](https://wordpress.org/support/topic/remote-parent-theme-absolute-or-relative-paths/#post-18720829)
 * much appreciated 🙂
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Remote parent theme (absolute or relative paths)?](https://wordpress.org/support/topic/remote-parent-theme-absolute-or-relative-paths/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [8 months, 3 weeks ago](https://wordpress.org/support/topic/remote-parent-theme-absolute-or-relative-paths/#post-18720812)
 * Right, so conceptually I should think of things as if the parent and child themes
   are hardcoded to require being in the same directory, and speak to my webhost
   about whether I can symlink from the first site’s /themes directory, to the second?
 * So I’d have:
    - /public_html/site_one/wp-content/themes/parent_theme
    - /public_html/site_two/wp-content/themes/parent_theme(symlink)
    - /public_html/site_two/wp-content/themes/child_theme
 * Is that the easiest / best way to go about it?
 * Thanks.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Get (and echo) Revision Date?](https://wordpress.org/support/topic/get-and-echo-revision-date/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/get-and-echo-revision-date/#post-18548723)
 * > Your assumption is correct 🙂
 * Excellent, in that case I’ll mark the question as resolved. Much appreciated.
 * Cheers 🙂
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Get (and echo) Revision Date?](https://wordpress.org/support/topic/get-and-echo-revision-date/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/get-and-echo-revision-date/#post-18547376)
 * haha, nice catch, late night message replying, all my php code is `<?php` etc
   in my theme files.
 * But yes, that’s my level of php fluency that I didn’t recognise it myself.
 * I managed to get it all working, after figuring out what could and could not 
   sit within echo’d html. This isn’t throwing up any errors, and produces a wonderful
   conditional result where there’s nothing output on posts where I haven’t added
   the custom field:
 *     ```wp-block-code
       function mytheme_get_the_original_date() {	$first = get_post_meta( get_the_ID(), 'first_published_date', true );	if ( ! empty( $first )) {		echo '<p class="entry-meta entry-meta-footer mod-date">				<span class="pre-in first-published">' , $first , '</span>				<span class="in">: Initial</span>			</p>';	}}
       ```
   
 * Assuming that’s all good and correct, thankyou so much for bearing with me on
   this little learning journey. It’s really been a significant improvement in my
   understanding of the system.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Get (and echo) Revision Date?](https://wordpress.org/support/topic/get-and-echo-revision-date/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/get-and-echo-revision-date/#post-18544928)
 * Oh so I was correct to put the echo into the curly braces for the functions.php
   part? If so, that was a bit of a conceptual leap for me, so I really appreciate
   your patience in answering my questions on this.
 * Thankfully, I’m the only person who needs to deal with my code or my themes, 
   but I do need to deal with it every few years, and coming back to it a couple
   of years later, being able to just see:
 *     ```wp-block-code
       <php? mytheme_get_the_original_date() ?>
       ```
   
 * …is probably a little cleaner for me when reading it. I’m mostly editing my template
   files from a what-goes-where perspective, not a how-it-works one.
 * I find stuff being in functions.php is easier to deal with when building it up
   myself, but is harder to understand what a theme is doing, when trying to reverse-
   engineer it for customisation etc. That’s largely why I spent a couple of years
   on and off trying to build an entire new theme from scratch – so I’d know how
   every bit of it worked, and could document that in the comments.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Get (and echo) Revision Date?](https://wordpress.org/support/topic/get-and-echo-revision-date/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/get-and-echo-revision-date/#post-18543739)
 * For perspective, I’m coding my themes from scratch, as .php classic template 
   files.
 * One thing I found worked well for me cognitively with the programming theory 
   lessons I was doing (Swift Playgrounds), was creating custom functions so that
   instead of putting all the functional code inline at the point it’s used, you
   put all that in the non-running part of the file in discreet units of functionality,
   with an arbitrary name, and then at the place you want it to run, you just have
   the function name reference.
 * So the code I made ended up being effectively just a running list of references.
 * It made sense to me from a compartmentalisation perspective, and I’ve tended 
   to do that with functions in my wordpress theme building, so I try to have:
 *     ```wp-block-code
       <php? my_utility_function() ?>
       ```
   
 * …and then all the actual stuff it does kept in the functions.php file. Buuut 
   I know so little about how wordpress and php function that I really only learn
   things by seeing the completed example – I don’t have the knowledge base to build
   up, but I can backfill that knowledge by working backwards from the completed
   example (like the ones provided in this thread). Thats just how I learn if I’m
   not in a classroom with a live tutor.
 * So to my way of how I like to do things, I’d want to make the template file have
   something like this:
 *     ```wp-block-code
       <!-- begin originally published date entry --><php? mytheme_get_the_original_date() ?><!-- end originally published date entry -->
       ```
   
 * So, would this be close to the answer for functions.php:
 *     ```wp-block-code
       function mytheme_get_the_original_date() {    $first = get_post_meta( get_the_ID(), 'first_published_date', true );    if ( ! empty( $first )) {        echo "First published: $first";        }    }
       ```
   
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Get (and echo) Revision Date?](https://wordpress.org/support/topic/get-and-echo-revision-date/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/get-and-echo-revision-date/#post-18542501)
 * Oh thanks… so if I’m interpreting this correctly (I only have the faintest knowledge
   of programming, but I’m trying to learn)…
 * You’re starting by declaring a variable (that’s just an arbitrary name, not a
   special wordpress signifier?), whose content is filled by the php command to 
   get the contents of the custom field, and then testing if the field’s value is
   NOT empty to echo a string “First Published:” followed by the contents of the
   variable. Is that correct?
 * That seems fairly comprehensible. Would it be better practice to have that implemented
   in the funchtions.php file (if you wouldn’t mind writing the code for that form
   of it), and just have a call to that function in my template file?
 * Thanks – that’s a solid new thing (setting an retrieving variables in php) I 
   learned.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Get (and echo) Revision Date?](https://wordpress.org/support/topic/get-and-echo-revision-date/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/get-and-echo-revision-date/#post-18542267)
 * Bearing in mind I’m operating at the edge of my knowledge here…
 * > If you’re simply going to display the field, you can save it in any format 
   > you wish.
 * OK, so having tested it, it’s literally just an arbitrary text string, rather
   than a date calculation call. That’s workable for me.
 * Is there a way I can make this happen so the text string “First Published:” doesn’t
   have to be in the custom field value itself?
 * e.g is there an addition that can be made to:
 *     ```wp-block-code
       <?php echo get_post_meta( get_the_ID(), 'first_published_date', true ); ?>
       ```
   
 * … which lets me put an echo of “First Published:” inside this, so it only shows
   if the first_published_date field has a recorded value?
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Get (and echo) Revision Date?](https://wordpress.org/support/topic/get-and-echo-revision-date/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/get-and-echo-revision-date/#post-18541760)
 * Could you please provide some more specificity for that? I add a new custom field
   to the post with:
 * name: first_published_date
 * value: do I need to enter the date in a specific format yyyy/mm/dd etc so that
   it matches whatever date style I’m using in the template to show the published
   date; eg:
 *     ```wp-block-code
       <?php the_time('Y/m/d') ?>
       ```
   
 * The reason I’m changing the published date is to make a particular post more 
   recent than a subsequent one, so when they’re both sticky, the older post shows
   up above the newer one in a descending by date home page… so how does this date
   interact with that, or do I still change the post date to control the page order,
   and this is just to get the decorative originally posted date that I set with
   the custom field?
 *   Forum: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
   
   In reply to: [Documentation for historical WP versions](https://wordpress.org/support/topic/documentation-for-historical-wp-versions/)
 *  Thread Starter [mattspace](https://wordpress.org/support/users/mattspace/)
 * (@mattspace)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/documentation-for-historical-wp-versions/#post-18483680)
 * Just because things are **changed**, doesn’t mean they’re _fixed_. IMHO apart
   from security fixes, almost everything WP has done since 4.8 has been to the 
   platform’s detriment. What you call “fixes”, I call “breaks”.

Viewing 15 replies - 1 through 15 (of 28 total)

1 [2](https://wordpress.org/support/users/mattspace/replies/page/2/?output_format=md)
[→](https://wordpress.org/support/users/mattspace/replies/page/2/?output_format=md)