Forum Replies Created

Viewing 15 replies - 61 through 75 (of 401 total)
  • Forum: Hacks
    In reply to: Adding text fields
    Jay

    (@phyrax)

    It’s all done within the theme, there are so many theme files I can’t just say “do it here”. Review the template hierarchy and that will tell you what file can load load what page.

    For example if you created a page named “my-awesome-page” – if your theme has a “page-my-awesome-page.php” file you would edit that, if not it falls back to page.php, etc…

    It’s entirely dependent on your theme, there is no one global answer.

    Jay

    (@phyrax)

    Actually you could do it with both term and meta data, to be 100% sure, granted I’m not entirely sure what start_date looks like ( it’s variable type ) so I’ll assume unix timestamp. This will save you a conditional check and meta query in the loop by grabbing all the right posts first.

    Something like this should work, but I’d test it in a dev environment first 🙂

    <?php
    
    function get_outdated_posts() {
    
    	$outdated_posts = get_posts( array(
    		'post_type'      => 'road_trip',
    		'post_status'    => 'publish',
    		'posts_per_page' => -1, // Get ALL posts
    		'tripstatus'     => 'upcomingadventures', // Use the slug of the term
    		'meta_key'       => 'start_date',
    		'meta_value_num' => current_time( 'U' ), // gets the current time based on wordpress blog settings in UNIX timestamp format.
    		'meta_compare'   => '<', // ie. less than current time.
    		'fields'         => 'ids',
    	) );
    
    	if ( empty( $outdated_posts ) ) {
    		return;
    	}
    
    	foreach ( $outdated_posts as $post_id ) {
    		wp_set_object_terms( $post_d, array( 11 ), 'trip_status', false ); // Overwrite it
    	}
    
    }
    Forum: Hacks
    In reply to: Remove a filter…..
    Jay

    (@phyrax)

    First time I looked at this, I tried the same thing you thought… then I realized, that is an apply_filters() call, not add_filter() You can only remove filters called by add_filter().

    Sorry, case of the mondays!

    Codex Apply Filters:
    https://developer.wordpress.org/reference/functions/apply_filters/

    Add Filter:
    https://developer.wordpress.org/reference/functions/add_filter/

    Remove Filters:
    https://developer.wordpress.org/reference/functions/remove_filter/

    Jay

    (@phyrax)

    There’s a few steps to this, so let me try and break them down with the limited amount of “I want to do this” information.

    1.) Determine what post type you want to edit
    BB press stores it’s forums, replies and topics as a post type in WordPress. They come in three flavors:

    • Forums
    • Topics
    • Replies

    2.) Determine what field(s) you want to edit. Sounds like maybe post content?
    You can see the usual post field keys here: https://codex.wordpress.org/Function_Reference/get_post_field

    3.) Write a WP_Query array to pull ALL the posts into one, then loop over them one by one, updating the post data you wish to update.

    The Snippet:
    https://gist.github.com/0b08a14c2f5576d52deef8aece6c43a3

    WARNING: Depending on the amount of posts pulling ALL posts may kill the PHP script’s execution, but I got ya this far, I’m sure you can figure out how to fix that 🙂

    Hope that helps, just hook the function where you want. But if I were you I’d use a $_GET parameter or something for a one-time run.

    Forum: Hacks
    In reply to: Adding text fields
    Jay

    (@phyrax)

    While I’m not familiar with Umbraco, I can say that doing the same with WordPress is still quite simple, though admittedly I’m kinda biast.

    Changing the layout of the page ( header position, content position, and featured image position ) is done at the template level in the code.

    Templates in WordPress are located ( typically ) at wp-content/themes/<your-theme-here> these templates follow the template hierarchy.

    By default WordPress doesn’t really provide any sort of table creator. However, in the spirit of WordPress – there’s a plugin for that: https://wordpress.org/plugins/table-maker/

    Hope that helps – good luck!

    Sweet, glad I could help – sounds like they’re not using WP_User::set_role(), they may be updating the user meta directly, in which case your hook wouldn’t work.

    Good luck

    Okay I did a quick test and I’m not having a problem getting the $new_role by using normal means ( creating a user in the wp-admin and swapping roles ).

    Every time I change the role, I still get a role value for $new_role.

    So, that brings to light more questions. What are you doing outside of standard user manipulation in the wp-admin? This block of code isn’t your problem, it’s somewhere else.

    If you’re transitioning the user’s role somewhere else that might be it, and if so, paste the code?

    Igor – could you provide your code? According to the codex here: https://codex.wordpress.org/Plugin_API/Action_Reference/set_user_role the action is definitely supposed to fire every time.

    This relies on the WP_User::set_role() method here: https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/class-wp-user.php#L566

    Note: Please use a gist if it’s a large amount of code.

    There is no short-code for this plugin, it hooks directly into a few different places, and achieving that with a short-code would require refactoring it a bit.

    However, you could use this filter https://github.com/JayWood/content-warning-v3/wiki/Dev-Documentation#hide-the-dialog-on-certain-pages-regardless-of-cookies

    By setting the plugin to site-wide, and returning false in this filter you can essentially show the dialog where you want.

    Sorry for the insanely late reply. The buttons are indeed there, but aren’t showing due to some CSS issues. This isn’t an issue with the plugin, rather a conflict with existing styles in the theme.

    You can verify the buttons are indeed there by viewing the source of your page. You’ll have to make use of the custom CSS or add/edit css to your theme to fix this.

    Forum: Hacks
    In reply to: Image updating automaticaly

    Looks about right for the switch statement, now to get the images for those days. Looks like you’re on the right track.

    Custom field values are not readable by wp_insert_post, you’re looking for post meta.

    https://codex.wordpress.org/Function_Reference/update_post_meta
    https://codex.wordpress.org/Function_Reference/add_post_meta

    Unfortunately I can’t really see what you see ( I don’t have your database ). So, if line 46 is empty ( on the last gist ) then something is wrong.

    I would start dumping data to your error log and watch it to see where it’s failing, you can do this very simply by enabling WP_DEBUG which you should if you’re developing anyhow.

    Then just start dropping error_log calls like so:

    error_log( print_r( $var, true ) );

    Swapping $var for the variable you’re logging of course. I would probably do this at minimum on lines 32, 35, and 39.

    Line 32 I’d log $location_data and lines 35 & 39 I’d log it as well, though with some sort of identifier as to which if statement your in, something like this:

    error_log( 'IF TRUE' . print_r( $var, true ) );

    I could have just misunderstood how the location_data is grabbed or how it looks. Or, as I like to say, I’m not perfect, and could’ve botched it somewhere along the line, but only a debug log can tell.

    Not to put a shameless plug here, but I wrote a pretty extensive article on debugging in WordPress, might be worth a read: https://webdevstudios.com/2015/10/15/debugging-wordpress-tips-snippets/

    Unfortunately I don’t know what your data looks like, so I’m kind of limited in what I can help you with, but I hope this at least points you in the right direction.

    Strip out the html, head, meta and body tags ( opening and closing ). You can drop the script tag as well that’s calling up javascript ( its at the bottom ).

    That’ll leave you with bare bones HTML content, now you need to add the header/footer calls and name the template, so this barebones should do ( not counting your HTML ):

    <?php
    
    /**
     * Template Name: My Template
     */
    
    get_header();
    
    ?>
    	<!-- Insert your HTML content immediately after this line -->
    <?php
    
    get_footer();

    Now, once that’s done save that file and drop it in your theme, name it something like page-my-template.php

    Once you do that go create a new page in WordPress and set the template to My Template – it should be in a dropdown on the right, if you did all this right.

    Boom, done! – This is a crude, and very simplistic explanation of page templates, if you get hung up, take a read at the official documentation on Page templates.

    You will undoubtedly need to clean up styling, etc, and there are MANY other ways of doing this ( considering you’re only doing a form ), but it should get you on the right track.

    Good luck – happy coding!

    Forum: Hacks
    In reply to: Image updating automaticaly

    What you’re asking is definitely possible, how to implement it however, depends on the widget.

    What you might do is look into how the widget is pulling in these pictures. Once you have that down you’ll want to work on your conditional, for something like this:

    if ( 'thrusday' == $current_day ) { //... do stuff }

    To check the current day of the week look into PHP’s date function here: http://php.net/manual/en/function.date.php

    If you want your dates to work off of the WordPress time, not your server time, use this as the timestamp for date in PHP: https://codex.wordpress.org/Function_Reference/current_time

    I would start deconstructing and attempting to understand the widget code first, before you jump right into coding.

Viewing 15 replies - 61 through 75 (of 401 total)